Skip to main content

ccompose

ccompose is a C11 wrapper around Clay that adds declarative blocks inspired by Jetpack Compose to Clay's immediate-mode layout engine. It includes an optional raylib rendering backend.

#include "ccompose.h"

int main(void) {
CC_SetWindow(960, 640, "Hello");
CC_Init();
while (CC_Running()) {
CC_Begin();
Column("Root",
.layout = { .sizing = { Grow(), Grow() },
.padding = PadAll(24),
.childAlignment = { .x = AlignXCenter(),
.y = AlignYCenter() } },
.backgroundColor = Color(18, 18, 20, 255)) {
Text("Hello, ccompose!",
.textColor = Color(255, 255, 255, 255),
.fontSize = 32);
}
CC_End();
}
CC_Shutdown();
return 0;
}

ccompose is at v0.1.5. Its macros, lifecycle helpers, and build layout may change between 0.x releases. Pin the tag or commit you depend on.

Key ideas​

  • Every container macro (Column, Row, Box, Button) opens a Clay element. Fields map directly to Clay_ElementDeclaration. Button also lowers its background alpha while hovered or pressed.
  • Containers use a single-iteration for loop, so Column(...) { ... } compiles as C11.
  • The raylib backend is enabled by default. Use -DCCOMPOSE_BACKEND_RAYLIB=OFF for headless builds, CI, and tests.
  • Clay owns the layout arena. ccompose adds no allocations after CC_Init().

Getting started​

  • Getting started: build, run the demo, first program
  • Building: per-platform builds, cross-compiling, headless, CMake options, using ccompose in your project
  • Web (WASM): Emscripten build, CC_RUN_LOOP, link flags, assets
  • Lifecycle: CC_Init, the frame loop, fonts, window configuration
  • Architecture: how ccompose, Clay, and raylib fit together

Building UI​

  • Containers: Column, Row, Box, Element and the control-flow rules
  • Text: the Text macro, font loading, global color, wrap & alignment
  • Images: Image, CC_ImageRef, scale modes, rounded corners, texture loading
  • Layout: sizing (Fit / Grow / Fixed / Percent), padding, child gap, alignment
  • Spacer and divider: auto-id flexible spacers and rule lines
  • Progress: LinearProgress and CircularProgress, with a value or animated
  • Styling: background, corner radius, borders, shadows, aspect ratio
  • Interaction: Button with default hover and press feedback, CC_Hovered, CC_Clicked
  • Floating: tooltips, modals, anchored overlays
  • Scroll and clip: CC_Scroll, drag + wheel input, .clip viewports
  • Custom drawing: escape hatch for arbitrary raylib draw calls inside the layout
  • Transitions: DefineTransition, slide/fade presets, easing functions

Reference​

Minimum viable program​

This program opens a window and draws text with raylib's default font:

CC_SetWindow(800, 600, "hi");
CC_Init();
while (CC_Running()) {
CC_Begin();
Column("Root",
.layout = { .sizing = { Grow(), Grow() },
.childAlignment = { .x = AlignXCenter(),
.y = AlignYCenter() } }) {
Text("hi", .textColor = Color(255,255,255,255), .fontSize = 48);
}
CC_End();
}
CC_Shutdown();

See Getting started for the CMake commands and Building for platform notes.