Containers
Containers are scoped blocks that open an element, run the block for its children, and close it again. Column and Row flow children in one direction, Box stacks them on top of each other, and Button is a Row that reacts to the pointer. Every Clay element field is available as a designated initializer.
All containers take a string-literal id first ("" for anonymous), then any CC_ElementDeclaration fields, then a { ... } block of children.
Example
static void card(void) {
Column("Card", .layout = { .padding = PadAll(16), .childGap = 8 },
.backgroundColor = ColorHex(0x1E1E22),
.cornerRadius = RadiusAll(8)) {
Text("Title", .fontSize = 20);
Row("Actions", .layout = { .childGap = 8 }) {
Button("Ok", .layout = { .padding = PadSymmetric(12, 6) },
.backgroundColor = ColorHex(0x2D6CDF)) {
Text("OK", .fontSize = 14);
}
}
Box("Badge") { // children stack, last on top
Text("NEW", .fontSize = 12);
}
}
}
Reference
| Name | Form | What it does | Page |
|---|---|---|---|
Column | Column("id", .field = ...) { } | Children flow top to bottom. | Containers |
Row | Row("id", .field = ...) { } | Children flow left to right. | Containers |
Box | Box("id", .field = ...) { } | Z-stack: the first child sets the size, later children are layered on top. | Containers |
Element | Element(direction, "id", .field = ...) { } | Generic container with a direction chosen at runtime (CC_LEFT_TO_RIGHT or CC_TOP_TO_BOTTOM). | Containers |
Button | Button("id", .field = ...) { } | A Row that dims its background while hovered (×0.85) and pressed (×0.70). | Interaction |
CC_OpenElement | CC_Scope (CC_String id, CC_LayoutDirection dir, CC_ElementDeclaration decl) | Runtime hook behind Column, Row and Element. | Architecture |
CC_OpenBox | CC_Scope (CC_String id, CC_ElementDeclaration decl) | Runtime hook behind Box. | Containers |
CC_OpenButton | CC_Scope (CC_String id, CC_ElementDeclaration decl) | Runtime hook behind Button. | Interaction |
CC_CloseScope | void (CC_Scope *scope) | Closes an element opened by one of the hooks above. Idempotent. | Architecture |
CC_Scope | struct { int active; } | Loop-guard state the container macros create. | Architecture |