Skip to main content

Module measure

Module measure 

Source
Expand description

Asking the Renderer how big something will be, while the Host is laying it out.

A Host that lays out a page itself (a flexbox, a grid, text flowing around a picture) needs to know how wide a run of text is before it can decide where anything goes, and only the side that draws the letters can say: the font, the density, the system’s font scale and the design system’s type scale are all the Renderer’s. So the Host asks, in the middle of its own work, and the Renderer answers on the same call stack.

One call carries many questions. A sidebar lays out a couple of hundred labels, and a flexbox asks each of them for its narrowest width, its widest width and its height at a given width, so one call per question would pay the crossing six hundred times.

The questions travel the way a batch does: fixed-length records first, then the strings and run lists they point at. The answers come back as fixed-length records in an array the Host owns. Nothing is serialised and nothing is copied on the way across.

Application code does not call the boundary. A layout engine asks measurer for a Measurer, which it gets only while the Host is inside one of its own calls, which is the only time the Renderer is standing still on the other end of the same thread.

Structs§

MeasureRequests
A set of questions for one call, built up and then asked at once.
MeasureResult
The Renderer’s answer to one request, in dp.
Measurer
The right to ask, for the length of one Host call.
NodeConstraints
The size a node may take, in dp. f32::INFINITY is no limit.
TextStyle
How a run of text is set, as the Renderer reads it.

Enums§

MeasureError
Why nothing was measured.
MeasureStatus
How one request went.
TextConstraint
How wide the text may be.

Constants§

CONSTRAINT_AT_MOST
The text broken into lines no wider than the given width.
CONSTRAINT_MAX_CONTENT
The text with no line broken except where it says so.
CONSTRAINT_MIN_CONTENT
The narrowest the text can be: its longest piece that cannot be broken.
FAKE_FONT_SIZE
The font size the mock takes for text that does not give one.
FLAG_TRUNCATED
The text had more lines than max_lines allowed, and some were not shown.
MEASURE_KIND_AT
MEASURE_NODE
A node the Renderer has already applied, and size constraints.
MEASURE_OFF_UI_THREAD
The call came from a thread other than the Renderer’s UI thread, and nothing was measured. The same number run gives for the same mistake.
MEASURE_RECORD_LEN
Bytes of one request record, whichever kind it is.
MEASURE_RESULT_LEN
Bytes of one result record.
MEASURE_TEXT
A run of text, its style and a width constraint.
MEASURE_UNAVAILABLE
There is nothing to measure with yet: the Renderer has not composed its first frame, so it has no density, no fonts and no design system. Also what a build with no renderer answers.
MEASURE_UNREADABLE
The request buffer as a whole cannot be read: shorter than its records, or null.
NODE_ID_AT
NODE_MAX_HEIGHT_AT
NODE_MAX_WIDTH_AT
NODE_MIN_HEIGHT_AT
NODE_MIN_WIDTH_AT
NODE_ZOOM_AT
RESULT_FIRST_BASELINE_AT
RESULT_FLAGS_AT
RESULT_HEIGHT_AT
RESULT_LAST_BASELINE_AT
RESULT_LAST_LINE_WIDTH_AT
RESULT_LINE_COUNT_AT
RESULT_MALFORMED
The record points outside the buffer, or is a kind or value the Renderer does not know.
RESULT_OK
RESULT_STATUS_AT
RESULT_UNKNOWN_NODE
The node is not in the Renderer’s table: never sent, removed, or sent in the batch the Host is computing right now, which the Renderer applies only once the call returns.
RESULT_WIDTH_AT
TEXT_ABSOLUTE_SIZE_AT
TEXT_CONSTRAINT_AT
TEXT_FONT_COUNT_AT
TEXT_FONT_OFFSET_AT
TEXT_FONT_SIZE_AT
TEXT_FONT_WEIGHT_AT
TEXT_ITALIC_AT
TEXT_LETTER_SPACING_AT
TEXT_LINE_HEIGHT_AT
TEXT_MAX_LINES_AT
TEXT_OVERFLOW_WRAP_AT
TEXT_SPANS_COUNT_AT
TEXT_SPANS_OFFSET_AT
TEXT_SPAN_FONTS_COUNT_AT
TEXT_SPAN_FONTS_OFFSET_AT
TEXT_TAB_SIZE_AT
TEXT_TEXT_LENGTH_AT
TEXT_TEXT_OFFSET_AT
TEXT_TYPE_ROLE_AT
TEXT_WIDTH_AT
TEXT_WORD_BREAK_AT
TEXT_WRAP_AT
TEXT_ZOOM_AT

Functions§

measurer
A measurer, if the Host is inside one of its own calls on this thread, which is the only time there is a Renderer standing still to answer.