Sizing, padding and alignment sugar
Short helpers for the values inside .layout. Sizing helpers pick how big an element is on each axis, padding helpers set the inner spacing, and alignment helpers position the children.
Example
static void layout_demo(void) {
Row("Bar", .layout = { .sizing = { Grow(), Fixed(48) }, // full width, 48px tall
.padding = PadSymmetric(16, 8),
.childAlignment = ChildAlign(.y = AlignYCenter()) }) {
Column("Side", .layout = { .sizing = { GrowMinMax(120, 240), Grow() } }) {}
Column("Main", .layout = { .sizing = SizingAll(Grow()) }) {}
Column("Half", .layout = { .sizing = { Percent(0.5f), Fit() } }) {}
}
}
Reference
| Name | Form | What it does | Page |
|---|---|---|---|
Fit | Fit() | Shrink to the children. The default. | Layout |
Grow | Grow() | Take the remaining space, shared with sibling Grow()s. | Layout |
Fixed | Fixed(n) | Exactly n pixels. | Layout |
Percent | Percent(p) | Fraction of the parent, p from 0.0 to 1.0. | Layout |
GrowMinMax | GrowMinMax(min, max) | Grow() bounded to [min, max] pixels. max 0 is unbounded. | Layout |
FitMinMax | FitMinMax(min, max) | Fit() bounded to [min, max] pixels. max 0 is unbounded. | Layout |
SizingAll | .sizing = SizingAll(Grow()) | Same sizing on both axes. | Layout |
SizingOnly | .sizing = SizingOnly(.width = Fixed(200)) | Set one axis by name. The other is Fit(). | Layout |
PadAll | PadAll(n) | n on every side. | Layout |
PadSymmetric | PadSymmetric(h, v) | h left and right, v top and bottom. | Layout |
PadOnly | PadOnly(.left = 8, .top = 4) | Per side. Unset sides are 0. | Layout |
AlignXStart, AlignXCenter, AlignXEnd | .childAlignment.x = AlignXCenter() | Horizontal child alignment. | Layout |
AlignYStart, AlignYCenter, AlignYEnd | .childAlignment.y = AlignYCenter() | Vertical child alignment. | Layout |
ChildAlign | .childAlignment = ChildAlign(.x = ..., .y = ...) | Both axes in one expression. | Layout |