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 = AlignXStart(), .y = AlignYStart() },
}) { ... }.sizing is a pair of CC_SizingAxis values — one for width, one for height. ccompose provides per-axis helpers and a pair of struct shortcuts:
| Helper | Returns | Meaning |
|---|---|---|
Fit() |
CC_SizingAxis |
Shrink-wrap around the element's children (+ padding). Clay's default. |
Grow() |
CC_SizingAxis |
Consume all remaining space on this axis, shared proportionally between siblings. Like CSS flex: 1. |
Fixed(px) |
CC_SizingAxis |
Exactly px pixels on this axis. |
Percent(p) |
CC_SizingAxis |
p × parent-size, with p a float in [0.0, 1.0]. Clay errors out on values outside this range. |
SizingAll(s) |
CC_Sizing |
Both axes use the same sizing — e.g. SizingAll(Grow()). |
SizingOnly(.width = ..., .height = ...) |
CC_Sizing |
Designated init; unspecified axis defaults to Fit(). |
.layout = { .sizing = SizingAll(Grow()) } // fill the container
.layout = { .sizing = SizingOnly(.width = Fixed(220),
.height = Grow()) } // sidebar
.layout = { .sizing = SizingOnly(.width = Grow()) } // horizontal bar, height = Fit()
.layout = { .sizing = { Percent(0.5f), Grow() } } // literal pair still worksFit() / 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 CC_Padding with .left, .right, .top, .bottom. ccompose follows a Flutter-style All / Symmetric / Only pattern:
| Helper | Meaning |
|---|---|
PadAll(n) |
n pixels on all four sides. |
PadSymmetric(h, v) |
h on left/right, v on top/bottom. |
PadOnly(.left = ..., .top = ..., .right = ..., .bottom = ...) |
Designated init; unspecified sides default to 0. |
.layout = { .padding = PadAll(16) }
.layout = { .padding = PadSymmetric(20, 12) } // horizontal=20, vertical=12
.layout = { .padding = PadOnly(.left = 16, .top = 8) } // others = 0Padding 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).
Helpers are axis-tagged so X-axis and Y-axis values can't be silently mixed up:
| Axis | Helper | Meaning |
|---|---|---|
.x |
AlignXStart() |
left-aligned (default) |
.x |
AlignXCenter() |
horizontally centered |
.x |
AlignXEnd() |
right-aligned |
.y |
AlignYStart() |
top-aligned (default) |
.y |
AlignYCenter() |
vertically centered |
.y |
AlignYEnd() |
bottom-aligned |
For the whole field there's also ChildAlign(.x = ..., .y = ...):
.layout = { .childAlignment = ChildAlign(.x = AlignXCenter(),
.y = AlignYCenter()) }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 = AlignYCenter() } }) { ... }
// A Column that centers itself within the screen:
Column("Centered",
.layout = { .sizing = { Grow(), Grow() },
.childAlignment = { .x = AlignXCenter(),
.y = AlignYCenter() } }) { ... }Column forces CC_TOP_TO_BOTTOM, Row forces CC_LEFT_TO_RIGHT, Box layers its children instead of flowing them (see Containers). 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 = AlignXCenter() } // 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 = AlignYCenter() } }) {
Button("Cancel", ...) { Text("Cancel", ...); }
Button("OK", ...) { Text("OK", ...); }
}
}