Skip to main content

Module layout

Module layout 

Source
Expand description

Layout. A UI is a tree of boxes: each lays out its children in a row, a column, a grid, or a stack, and each child sizes itself to fit its content, at a fixed size, or as a share of the leftover room.

Boxes are kept in one list in pre-order. Sizes come from four passes over it, never by trial: widths bottom-up (each box tells its parent what it needs), then top-down (each takes its share); text wraps to the widths it got; then heights the same way. Each pass visits each box once.

What the app sets on a box (Spec) is kept apart from what layout computes (Place), and positions are relative to the parent. So a run where nothing layout reads changed keeps every Place, and scrolling moves content without any relayout.

Structs§

Placement
Where a box places itself, horizontally and vertically. An Align alone sets both (Align::End: the far corner, Align::Center: the middle); a pair sets each ((Align::End, Align::Center): right, vertically centred). (One non-zero byte, so Option<Placement> costs boxes without one nothing: every box is copied as it is described, and 8 more bytes per box made describing a window a sixth slower.)

Enums§

Align
Where children sit when there is room to spare.
Flow
How a box lays out its children.
Length
A box’s size along one axis.