Skip to main content

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​

NameSignatureWhat it doesPage
CC_SetWindowvoid (int width, int height, const char *title)Window size and title. Call before CC_Init.Lifecycle
CC_SetWindowFlagsvoid (unsigned int raylib_flags)raylib FLAG_* bits (resizable, MSAA, vsync). Call before CC_Init.Lifecycle
CC_SetBackgroundvoid (CC_Color color)Clear color used at the start of every frame.Lifecycle
CC_SetErrorHandlervoid (void (*handler)(CC_ErrorData))Replace the default Clay error printer. Call before CC_Init.Lifecycle
CC_Initvoid (void)Open the window, set up the Clay arena and fonts, register CC_Shutdown with atexit.Lifecycle
CC_Shutdownvoid (void)Unload fonts, close the window, free the arena. Safe to call twice.Lifecycle
CC_Runningbool (void)Main-loop condition. False once the window is closed or the exit key is pressed. Always true headless.Lifecycle
CC_Beginvoid (void)Start a frame: read input, reset per-frame pools, begin the Clay layout.Lifecycle
CC_EndCC_RenderCommandArray (void)Finish the layout, draw it, present. Returns the render commands.Lifecycle
CC_RUN_LOOPCC_RUN_LOOP(frame_fn)Portable main loop: a while natively, emscripten_set_main_loop on the web.Web (WASM)
CC_SetViewportvoid (float width, float height)Layout size for headless runs. No effect with raylib, which reads the window size every frame.Headless mode