Skip to main content

Module measure

Module measure 

Source
Expand description

The host MEASURE contract. The VAPP-4 verdict: never one FFI upcall per taffy measure call (taffy asks a leaf 10–15 times per pass). The core batches: ONE upcall for the intrinsic widths of every dirty leaf (with the resolved text style, so Compose can pick the font before its first pass), taffy runs against a Rust-side memo, ONE upcall for the heights at the widths taffy decided, and a third round only when a height changed a width decision (counted in LayoutOutput::measure_rounds). In-process painters (gpui) may answer per request through DirectMeasure; nothing crosses an FFI there.

Structs§

ControlBox
The control box a leaf’s recipe fixes (padding inside the measured size, definite sizes taffy already knows). The measurer adds the padding around the content it shapes and honours min_*. padding_horizontal / padding_vertical are the AVERAGES of the two sides (a measurer adding 2 × padding gets the exact total); padding has every side.
DirectMeasure
The per-request form for in-process painters (gpui): one closure that answers (leaf, wrap_width) with a size. None = unconstrained (max-content); Some(0.0) = min-content. No baselines (see DirectMeasureWithBaseline).
DirectMeasureWithBaseline
DirectMeasure whose closure also answers the first baseline: (leaf, wrap_width) → (width, height, baseline).
FixedMeasure
The geometry-test measure every platform reproduces exactly: 8 px per character on ONE 20 px line (no wrapping), fixed boxes per control, or an explicit size per node id (fixtures/layout-geometry.json measures).
HeightRequest
Second phase: the height of leaf index when laid out width wide.
Intrinsics
What the host answers for one leaf: the width it needs with every line break taken (min_content), with none (max_content), the height at max_content width (one line for text) and the FIRST BASELINE from the top of the border box (alignItems: baseline; it does not move with the width: the first line stays the first line). None = no baseline (an icon, a box): the bottom edge stands in, like CSS. Controls with a fixed box return it in both widths.
LeafRequest
One leaf the host must measure. index names the layout node; the host keys its own caches on it. lines = the Text prop (truncate to N lines).
MeasureMemo
The Rust-side memo taffy’s measure closure answers from. Keyed by layout node index; content_version bumps clear a leaf’s entries.
MeasureRequest
A measured leaf’s answer for one taffy request, from the memo. width taffy already knows wins; else the available space picks min/max content; a definite available width clamps max-content (text wraps).
TextStyle
Typography a measured leaf is laid out with (the theme’s resolved recipe).

Constants§

FIXED_ASCENT
The fixed measure’s ascent: a 20 px line’s baseline sits 15 px down.
FIXED_CHAR_WIDTH
FIXED_LINE_HEIGHT

Traits§

Measure
Implemented by the host. Both calls receive batches; the core never calls them per taffy request.

Functions§

finite_or_zero
v when finite and non-negative, else 0 (R8 F53: a host’s NaN, ±inf or negative size never reaches the memo or taffy).