Skip to main content
Layout is all integers. No heap during measure or place. Every node has a LayoutSpec. Containers (row, column, stack, grid, scroll_area) place children inside the rect the parent got.

Node kinds (NodeKind)

Constructors:
For stack, grid, and scroll_area, set kind and children on a SurfaceNode struct:
scroll_area turns on scissor clipping automatically. Pair it with app-managed scroll offset and a UniformList when virtualizing long lists (see Input and overlays).

Size rules (SizeRule)

Set on LayoutSpec.width and LayoutSpec.height independently.

Flex weights

When multiple siblings use .fill on the same axis, space splits by layout.flex (default 1):
In a row, the first child gets 200 px width; the second takes the rest.

LayoutSpec fields

Alignment (AxisAlign)

start, center, end, stretch. In a row, align_y positions children vertically. stretch makes cross-axis .fill children expand to the container height. In a column, align_x positions children horizontally.

Padding and gap

  • padding: inset applied before laying out children
  • gap: pixels between adjacent children on the main axis
Use ui.Padding.uniform(12) or per-edge { .north = 8, .south = 8, .east = 16, .west = 16 }.

Measure and place pipeline

  1. measureNode: bottom-up intrinsic sizes
  2. applySizing: map measured size + parent bounds + LayoutSpec to final rect
  3. placeNode: emit draws, register hits, recurse into children
Leaf measurement examples:

Container recipes

Toolbar row

Overlay stack (dim + dialog)

Use kind = .stack when a panel and its scrim share one area, or queue a separate overlay in finish() for popups anchored to a control (preferred for dropdowns).

Settings-style form grid

grid with grid_columns = 2 gives equal-width columns. Each cell is a child node (often a form_row leaf).

stack vs overlays

Overlays get higher hit z and run through shouldDismissOverlays().

Focus scopes

Set focus_scope = true on a container node to keep keyboard focus traversal inside a panel (modals, sidebar sections). Child hits inherit the scope id.
  • UniformList / UniformGrid: compute visible item ranges for virtualized children (Input and overlays)
  • ScrollState: thumb position for scrollbar nodes
  • Element / findElement: debug inspector rects after render

Next