Skip to main content

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​

NameFormWhat it doesPage
ColumnColumn("id", .field = ...) { }Children flow top to bottom.Containers
RowRow("id", .field = ...) { }Children flow left to right.Containers
BoxBox("id", .field = ...) { }Z-stack: the first child sets the size, later children are layered on top.Containers
ElementElement(direction, "id", .field = ...) { }Generic container with a direction chosen at runtime (CC_LEFT_TO_RIGHT or CC_TOP_TO_BOTTOM).Containers
ButtonButton("id", .field = ...) { }A Row that dims its background while hovered (×0.85) and pressed (×0.70).Interaction
CC_OpenElementCC_Scope (CC_String id, CC_LayoutDirection dir, CC_ElementDeclaration decl)Runtime hook behind Column, Row and Element.Architecture
CC_OpenBoxCC_Scope (CC_String id, CC_ElementDeclaration decl)Runtime hook behind Box.Containers
CC_OpenButtonCC_Scope (CC_String id, CC_ElementDeclaration decl)Runtime hook behind Button.Interaction
CC_CloseScopevoid (CC_Scope *scope)Closes an element opened by one of the hooks above. Idempotent.Architecture
CC_Scopestruct { int active; }Loop-guard state the container macros create.Architecture