Layout
Columns, rows, grids, stacks, scrolling, and the modifiers that size and space them.
The ergonomic API is package ui.
| Constructor | Layout |
|---|---|
ui.Column(children...) |
Vertical flex (children stretch on the cross axis) |
ui.Row(children...) |
Horizontal flex (children vertically centered) |
ui.Stack(children...) |
Layered (z-order) |
ui.Center(child) |
Fill parent, center child |
ui.Spacer() |
Flex-grow filler |
ui.Grid(cols, children...) |
Equal-width columns |
ui.Scroll(id, child) |
Clip and scroll; id remembers offset |
ui.ViewOf(v) |
Wrap any View so modifiers chain |
ui.Raw(el) |
Wrap a bare *layout.Element |
ui.HLine / ui.VLine |
Rules |
ui.Icon(icon, size, color) |
Atlas sprite |
ui.Image(id, data) |
PNG/JPEG bitmap (ImageFile, ImageFS) |
ui.SVG(id, data) |
Custom SVG (SVGFile, SVGFS; currentColor follows text color) |
ui.TitleBar(children...) |
Custom window title bar; platform controls auto-included |
ui.WindowControls() |
Min/max/close for undecorated windows (usually via TitleBar) |
Children are ui.View. nil is skipped. Split UI into helpers that return ui.View.
Chain modifiers on *ui.Node:
.Gap .Padding .PaddingXY .PaddingLeft/Right/Top/Bottom
.Margin .MarginXY .MarginLeft/Right/Top/Bottom
.Wrap .Grow .Shrink .Width .Height .Frame .Size
.Align .Justify .Style .Background .BackgroundColor
.Disabled .DefaultFocusAlignment: ui.AlignStart|Center|End|Stretch, ui.JustifyStart|Center|End|Between.
.Float(corner, dx, dy) takes a node out of the flow and pins it to a corner of its parent, over the siblings before it — a button in the corner of an editor, for example:
ui.Column(
ui.ViewOf(editor).Grow(1),
ui.Button("fmt", ui.Text("Format")).Float(ui.CornerBottomRight, 22, 22),
).Grow(1)A pane that should fill leftover space needs .Grow(1) on itself and every ancestor up to the Body root. Root trees almost always end with .Grow(1).Background(ui.TokenSurface). A Row whose children should stretch vertically needs .Align(ui.AlignStretch).
Use c.Theme().Spacing (XXS 2px … XXXL 32px) instead of magic numbers. Typical: S 8, M 12, L 16.