Stack Layout (Flexbox)
Stacks are the primary layout primitive. Useui.row() for horizontal layout and ui.column() for vertical layout.
Basic Stack
Flex Properties
Control how children grow and shrink:flex— Grow factor (e.g.,flex: 1)flexShrink— Shrink factor when space is constrainedflexBasis— Initial size before growing/shrinking
Alignment
- Main Axis (justify)
- Cross Axis (align)
- Per-Child (alignSelf)
"start", "end", "center", "between", "around", "evenly"Wrapping
Enable line wrapping for responsive layouts:Grid Layout
Grid provides explicit two-dimensional layout with automatic or manual placement.Basic Grid
Explicit Placement
Place children at specific grid positions:Spanning Cells
Track Sizing
Define column/row sizes with fractions:Intrinsic Sizing
All widgets implementmeasureMinContent and measureMaxContent for automatic sizing.
How It Works
Min Content
The smallest size a widget can be without overflow. For text, this is the longest word. For containers, it’s the minimum size needed for children.
Max Content
The ideal size with no constraints. For text, this is the full unwrapped width. For containers, it’s the natural size of all children.
Examples
Layout constraints
Absolute Positioning
Position children absolutely within their parent:top, right, bottom, left
Spacing Scale
Rezi provides a consistent spacing scale:| Key | Value | Use Case |
|---|---|---|
0 | 0 | No spacing |
xs | 0.5 | Tight spacing |
sm | 1 | Related items |
md | 2 | Section separation |
lg | 4 | Major sections |
xl | 8 | Page-level spacing |
2xl | 12 | Maximum spacing |
Using spacing scale
Padding & Margin
All containers support padding and margin with directional shorthands:m, mx, my, mt, mr, mb, ml.
Performance
The Rezi layout engine is highly optimized:- Binary drawlist — Layout produces a compact binary representation sent to the native renderer
- Incremental layout — Only dirty subtrees are re-laid out
- Two-pass maximum — Wrapping stacks may require a second pass; all other layouts are single-pass
- No DOM — Direct terminal rendering without browser overhead
BENCHMARKS.md):
- Layout stress (grid with many cells): 347 ops/s (vs Ink: 36 ops/s)
- Tree construction (100 items): 3.1K ops/s (vs Ink: 38 ops/s)
- Virtual list (100K items): 1.0K ops/s (vs Ink: 44 ops/s)
For maximum performance, prefer
ui.column over ui.box when you don’t need borders. The box widget has additional overhead for border rendering and synthetic inner column creation.Best Practices
- Layout
- Sizing
- Spacing
- Use
ui.columnas your default container - Use
ui.rowfor horizontal arrangements - Use
ui.gridfor two-dimensional layouts - Reserve
ui.boxfor when you need borders or backgrounds
Next Steps
Styling
Learn about colors, typography, and style props
Theming
Customize your app’s visual appearance