Lifecycle and window
Every ccompose program follows the same shape: configure the window, call CC_Init() once, then run a loop that builds the UI between CC_Begin() and CC_End() every frame. Window settings are read by CC_Init(), so set them first. CC_RUN_LOOP is the portable form of the loop that also works in the browser.
Example
int main(void) {
CC_SetWindow(960, 640, "My app"); // before CC_Init
CC_SetWindowFlags(FLAG_WINDOW_RESIZABLE);
CC_SetBackground(ColorHex(0x121214));
CC_Init();
while (CC_Running()) { // false once the window closes
CC_Begin();
Column("Root", .layout = { .sizing = { Grow(), Grow() },
.padding = PadAll(24) }) {
Text("Hello", .fontSize = 24);
}
CC_End(); // lays out, draws, presents
}
CC_Shutdown();
return 0;
}
Reference
| Name | Signature | What it does | Page |
|---|---|---|---|
CC_SetWindow | void (int width, int height, const char *title) | Window size and title. Call before CC_Init. | Lifecycle |
CC_SetWindowFlags | void (unsigned int raylib_flags) | raylib FLAG_* bits (resizable, MSAA, vsync). Call before CC_Init. | Lifecycle |
CC_SetBackground | void (CC_Color color) | Clear color used at the start of every frame. | Lifecycle |
CC_SetErrorHandler | void (void (*handler)(CC_ErrorData)) | Replace the default Clay error printer. Call before CC_Init. | Lifecycle |
CC_Init | void (void) | Open the window, set up the Clay arena and fonts, register CC_Shutdown with atexit. | Lifecycle |
CC_Shutdown | void (void) | Unload fonts, close the window, free the arena. Safe to call twice. | Lifecycle |
CC_Running | bool (void) | Main-loop condition. False once the window is closed or the exit key is pressed. Always true headless. | Lifecycle |
CC_Begin | void (void) | Start a frame: read input, reset per-frame pools, begin the Clay layout. | Lifecycle |
CC_End | CC_RenderCommandArray (void) | Finish the layout, draw it, present. Returns the render commands. | Lifecycle |
CC_RUN_LOOP | CC_RUN_LOOP(frame_fn) | Portable main loop: a while natively, emscripten_set_main_loop on the web. | Web (WASM) |
CC_SetViewport | void (float width, float height) | Layout size for headless runs. No effect with raylib, which reads the window size every frame. | Headless mode |