Repository navigation
Layout
Layout is configured through .layout = { ... } on any container. It's a direct-through to Clay's Clay_LayoutConfig struct — ccompose doesn't rename or wrap any fields.
Column("Root",
.layout = {
.sizing = { Grow(), Grow() },
.padding = PadAll(16),
.childGap = 8,
.childAlignment = { .x = AlignStart(), .y = AlignTop() },
}) { ... }.sizing is a pair of Clay_SizingAxis values — one for width, one for height. ccompose provides four sugar helpers:
| Helper | Meaning |
|---|---|
Fit() |
Shrink-wrap around the element's children (+ padding). Clay's default. |
Grow() |
Consume all remaining space on this axis, shared proportionally between siblings. Like CSS flex: 1. |
Fixed(px) |
Exactly px pixels on this axis. |
Percent(p) |
p × parent-size, with p a float in [0.0, 1.0]. Clay errors out on values outside this range. |
.layout = { .sizing = { Grow(), Grow() } } // fill the container
.layout = { .sizing = { Fixed(220), Grow() } } // sidebar
.layout = { .sizing = { Grow(), Fit() } } // horizontal bar, height = content
.layout = { .sizing = { Percent(0.5f), Grow() } } // half-width panelFit() / Grow() also accept min/max bounds when you build the sizing struct directly:
.layout = { .sizing = { CLAY_SIZING_GROW(.min = 120, .max = 480), Grow() } }.padding is a Clay_Padding with .left, .right, .top, .bottom. ccompose provides:
| Helper | Meaning |
|---|---|
PadAll(n) |
n pixels on all four sides. |
Pad(left, right, top, bottom) |
Per-side, in that order. Note: not the CSS T/R/B/L convention. |
.layout = { .padding = PadAll(16) }
.layout = { .padding = Pad(20, 20, 12, 12) } // L, R, T, BPadding eats into the element's bounding box — it does not grow the box. A Fixed(100) element with PadAll(20) gives children a 60 × 60 content area.
.childGap is a flat integer: pixels of space between adjacent children on the main axis. It does not add leading or trailing space.
Column("List", .layout = { .childGap = 8 }) {
Text("A", ...);
Text("B", ...); // 8px below A
Text("C", ...); // 8px below B
}For divider lines between children (instead of just space), use .border.width.betweenChildren — see Styling → Borders.
.childAlignment controls how children are aligned within the parent's bounds on the cross axis (perpendicular to the layout direction).
| Axis | Helper | Meaning |
|---|---|---|
.x |
AlignStart() |
left-aligned (default) |
.x |
AlignCenter() |
horizontally centered |
.x |
AlignEnd() |
right-aligned |
.y |
AlignTop() |
top-aligned (default) |
.y |
AlignMiddle() |
vertically centered |
.y |
AlignBottom() |
bottom-aligned |
Behavior by direction:
-
Column(top-to-bottom):.xaligns each child horizontally within the parent's width..ycontrols how the stack sits within the parent's height. -
Row(left-to-right):.yaligns each child vertically within the parent's height..xcontrols how the row sits within the parent's width.
// A Row where every child is vertically centered inside the 40px bar:
Row("Bar",
.layout = { .sizing = { Grow(), Fixed(40) },
.padding = PadAll(8),
.childGap = 12,
.childAlignment = { .y = AlignMiddle() } }) { ... }
// A Column that centers itself within the screen:
Column("Centered",
.layout = { .sizing = { Grow(), Grow() },
.childAlignment = { .x = AlignCenter(),
.y = AlignMiddle() } }) { ... }Column forces CLAY_TOP_TO_BOTTOM, Row forces CLAY_LEFT_TO_RIGHT, Box uses CLAY_TOP_TO_BOTTOM. Setting .layout.layoutDirection on these is overwritten by the macro.
If you need a runtime-chosen direction, use Element(direction, ...) instead — see Containers → Element.
Column("Panel",
.layout = {
.sizing = { Grow(), Grow() }, // fill parent
.padding = PadAll(20), // inset children 20px
.childGap = 12, // stack spacing
.childAlignment = { .x = AlignCenter() } // center horizontally
},
.backgroundColor = Color(28, 28, 34, 255),
.cornerRadius = RadiusAll(8)) {
Text("Header", .textColor = Color(236,236,236,255), .fontSize = 24);
Text("Body", .textColor = Color(180,180,180,255), .fontSize = 14);
Row("Actions",
.layout = { .childGap = 8, .childAlignment = { .y = AlignMiddle() } }) {
Button("Cancel", ...) { Text("Cancel", ...); }
Button("OK", ...) { Text("OK", ...); }
}
}