Skip to main content

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​

NameFormWhat it doesPage
FitFit()Shrink to the children. The default.Layout
GrowGrow()Take the remaining space, shared with sibling Grow()s.Layout
FixedFixed(n)Exactly n pixels.Layout
PercentPercent(p)Fraction of the parent, p from 0.0 to 1.0.Layout
GrowMinMaxGrowMinMax(min, max)Grow() bounded to [min, max] pixels. max 0 is unbounded.Layout
FitMinMaxFitMinMax(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
PadAllPadAll(n)n on every side.Layout
PadSymmetricPadSymmetric(h, v)h left and right, v top and bottom.Layout
PadOnlyPadOnly(.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