Layout
Layout containers hold children and handle all size negotiation between them. Every container implements Component (so it can be nested anywhere) and Layout (so the framework can walk its children for theme propagation and focus collection).
Containers
| Container | Purpose |
|---|---|
| VBox and HBox | Stack children vertically or horizontally; the primary building blocks |
| Border | Wrap a child with a configurable box border and optional title |
| Padding | Add blank space around a child |
| ScrollView | Clip a child to a viewport with vertical scrolling |
| Grid | Rows × columns grid with equal cell sizes |
Spacers and wrappers
| Type | Purpose |
|---|---|
| Spacers (VFill, HFill, VGap, HGap) | Push, fill, or add fixed gaps between children |
| FlexChild | Wrap any component as a flex slot for inline use in variadic constructors |
| AlignChild | Per-child cross-axis alignment override |
Two-pass render pipeline
Every container follows the same two-pass contract:
- Measure — the parent calls
Measure(constraint)on each child to learn its desired size.Constraint.MaxWidth/MaxHeightare the available cells;-1means unconstrained. - Render — the parent calls
Render(buf, region)on each child with its allocatedRegion. The child draws intobufclipped to that region.
Never skip Measure before Render. Never store buf or region across frames.
AddChild vs AddFlexChild
The core sizing decision in every box layout:
AddChild(c)— natural size. The child takes exactly whatMeasurereturns.AddFlexChild(c, weight)— flex distribution. Leftover space is divided among flex children proportionally by weight.
See VBox and HBox for a full explanation with diagrams.
Import path
import "github.com/antoniocali/oat-latte/layout"