Spacer and divider
Use spacers for flexible gaps and dividers for separator lines. These five leaf macros take no id or child block and are safe to call in loops.
HSpacer(); // grows horizontal
VSpacer(); // grows vertical
Spacer(.width = Grow(), .height = Fixed(12)); // explicit per-axis sizing
HDivider(); // 1px horizontal line, default grey
HDivider(.thickness = 2, .color = Color(...)); // styled horizontal line
VDivider(); // 1px vertical line
VDivider(.thickness = 2, .color = Color(...)); // styled vertical line
Anonymous element ids
Spacers and dividers use anonymous elements because they need only layout. Named container ids must be unique per frame. See Container id guidance.
If you reused the id "Spacer" across multiple components in the same frame, Clay would emit:
ccompose/clay error: An element with this ID was already previously declared during this layout.
Each call opens an anonymous element with Clay__OpenElement(), and Clay generates a unique internal id. You can repeat calls inside loops:
for (int i = 0; i < rows; i++) {
Text(rows[i].label, ...);
HDivider();
}
HSpacer / VSpacer
HSpacer() uses .sizing = { Grow(), Fit() }. VSpacer() uses .sizing = { Fit(), Grow() }. Put HSpacer in a Row or VSpacer in a Column to fill the remaining main-axis space.
Row("Toolbar",
.layout = { .sizing = { Grow(), Fixed(40) },
.childAlignment = { .y = AlignYCenter() } }) {
Text("File", ...);
Text("Edit", ...);
HSpacer(); // pushes the next child to the far right
Text("Settings", ...);
}
Column("Card",
.layout = { .sizing = { Grow(), Fixed(400) },
.padding = PadAll(16) }) {
Text("Title", ...);
Text("Subtitle", ...);
VSpacer(); // pushes Actions to the bottom
Row("Actions") { Button(...) { ... } }
}
Growth applies on the parent's main axis, so HSpacer in a Column, or VSpacer in a Row, has no visible effect.
Spacer (per-axis sizing)
For a fixed gap, percentage gap, or growth on both axes, use Spacer(.width, .height) with Fit(), Grow(), Fixed(n), or Percent(p):
Spacer(); // fit / fit: zero-sized stub
Spacer(.width = Grow()); // like HSpacer
Spacer(.height = Grow()); // like VSpacer
Spacer(.width = Grow(), .height = Grow()); // grow on both axes (fills parent)
Spacer(.height = Fixed(12)); // 12px vertical gap in a Column
Spacer(.width = Percent(0.25f)); // 25% of parent's width
Both fields default to Fit() because Clay_SizingAxis zero-initializes to CLAY__SIZING_TYPE_FIT == 0. The options struct is:
typedef struct {
CC_SizingAxis width; // default Fit()
CC_SizingAxis height; // default Fit()
} CC_SpacerOpts;
Spacer is the same anonymous leaf as HSpacer / VSpacer, so it's loop-safe and has no ID, hover, or click hook.
HDivider / VDivider
Both take an optional designated-initializer CC_DividerOpts struct:
typedef struct {
float length; // Size along the flow axis in px. <= 0 grows.
float thickness; // Size across the flow axis. 0 uses 1.0 px.
CC_Color color; // alpha == 0 => built-in mid-grey default
} CC_DividerOpts;
HDividerruns along the X axis:.lengthcontrols width (defaults toGrow()),.thicknessis the height.VDividerruns along the Y axis:.lengthcontrols height (defaults toGrow()),.thicknessis the width.
Column("Menu", .layout = { .childGap = 8 }) {
Text("Item A", ...);
HDivider(); // 1px, default grey
Text("Item B", ...);
HDivider(.thickness = 2,
.color = Color(0x38, 0x3C, 0x44, 0xFF)); // thicker, custom
Text("Item C", ...);
}
Row("Inline", .layout = { .childGap = 12 }) {
Text("Home", ...);
VDivider();
Text("Docs", ...);
VDivider();
Text("Blog", ...);
}
Defaults
length:<= 0falls back toGrow()on the divider's flow axis.thickness:0falls back to1.0pixel.color:{0}(alpha zero) falls back to the built-in mid-grey (#50545C). Works regardless of whetherCC_Coloris byte or float.
Fixed-length dividers
Set .length for a divider shorter than its parent:
Row("ButtonRow", .layout = { .childAlignment = { .y = AlignYCenter() } }) {
Button("Save", ...) { Text("Save", ...); }
VDivider(.length = 48, .color = Color(0x38,0x3C,0x44,0xFF));
Button("Cancel", ...) { Text("Cancel", ...); }
}
Limitations
-
Pass
.colorexplicitly for a themed divider.CC_DividerDefaultColoris fixed. -
An anonymous divider cannot be targeted by
CC_HoveredorCC_Clicked. Use a namedBoxorButtonfor an interactive separator.
See also
- Containers: named, child-bearing elements.
- Layout:
.childGap,.childAlignment, and the full sizing model. - Styling: borders:
.border.width.betweenChildrenfor Clay-native dividers drawn as part of the container, instead of as separate elements. - Troubleshooting: duplicate-ID errors and how leaf macros avoid them.