Skip to main content

Crate rux_layout

Crate rux_layout 

Source
Expand description

Rux layout, milestones M1–M4.

A styled node tree fed through taffy (flexbox) to produce absolute paint items. Boxes come straight from taffy; text leaves are sized through a caller-supplied measure callback (so this crate stays free of any font dependency, the shell owns the text engine). See docs/04-architecture.md, Stage 4.

The crate is mostly its vocabulary. Style is the honored subset of CSS as the engine actually sees it, and Node is one styled element with its children. rux-style produces that tree; this crate turns it into the flat Paint list rux-paint consumes, in absolute coordinates with the cascade and the box model already collapsed into numbers.

Layout emits more than pictures, because a frame’s geometry is the only place several other questions can be answered honestly. Alongside the paint items come the regions the shell needs and cannot recompute for itself: HitRegion for pointer targets, ScrollRegion for what scrolls and how far, FocusRegion and FocusItem for tab order, SelectRegion for selectable text, StateRegion for hover and active, and AccessNode for the accessibility tree. All of them are in the same coordinate space as the paint items, which is the point: two places doing the same coordinate arithmetic eventually disagree, so there is one conversion and everyone reads its output.

Both flexbox and grid come from taffy. What does not come from taffy is text sizing, which is why measure is a callback: pulling a font stack into this crate would put shaping under layout, and the shell already owns one.

Structs§

Access
The accessibility facts about one node: what it is, what it’s called, and what state it’s in. Attached during the build and carried through layout so the shell can publish a tree with real geometry.
AccessNode
One element exposed to assistive technology, with the geometry it ended up occupying. Emitted in document order, and only for nodes whose role is meaningful, a plain layout box contributes nothing.
BoxShadow
A single (outer) box-shadow. Offsets, blur and spread are logical px.
FocusItem
One keyboard-focusable element, in document (Tab) order. Carries the geometry (for the focus ring) plus how the shell should act on it.
FocusRegion
An absolutely-positioned focusable region for an <input>, carrying its r-model signal name.
Gradient
A CSS gradient reduced to what the painter needs: a shape and colour stops.
HitRegion
An absolutely-positioned tappable region, carrying its @tap handler source.
ImageContent
An image carried by a leaf node. src is resolved to a path the painter can open; the intrinsic size is filled in by the runtime (it reads the file’s header) and sizes the box when CSS gives no width/height.
Layout
The result of laying out a tree: paint items, hit regions, and focus regions, all in painter’s/topmost-last order.
Node
A node in the view tree: a style, optional text, children, and an optional @tap handler (raw handler source, run by the shell on tap).
Offset
How far a scroller’s content has travelled, in logical pixels. Positive moves the content up / left, i.e. y is “how far down the content we are”.
PaintImage
An image scaled to fill its laid-out box.
PaintRect
A resolved, absolutely-positioned box: an optional fill and an optional border, sharing one rounded-rect geometry.
PaintText
A resolved, absolutely-positioned text block.
PaintTick
A checkmark stroked inside its laid-out box.
Rgba
Straight RGBA in the 0..=1 range. Renderer-agnostic.
ScrollRegion
A scrollable box. id is its index in tree order, stable across rebuilds as long as the tree’s shape is, which is what the shell keys offsets by.
SelectRegion
An absolutely-positioned type="select", carrying its bound options so the shell can open a dropdown and write the chosen value back to model.
Sides
Per-side box-model lengths (padding / margin / border widths).
StateRegion
An absolutely-positioned box whose styling depends on pointer state (:hover / :active), carrying the tree path that identifies it to the builder. Emitted only for nodes some pointer-state rule could match, so a document with no such rules produces none.
Style
The style subset M-series understands (a stand-in for the CSS ComputedStyle).
TextContent
Text carried by a leaf node.

Enums§

AccessRole
What an element is, for assistive technology. Deliberately a small enum owned by the layout rather than an accesskit type: the layout stays free of the platform a11y crate, and only the shell translates these.
Align
Cross-axis alignment (align-items).
Axis
How a node lays out its children. Defaults to Row to match CSS’s flex-direction initial value.
Background
A box background: a flat colour, a gradient, or an image.
Cursor
The mouse cursor shown while the pointer is over a box (cursor). Only the values the shell maps to a winit CursorIcon are modelled; the default is the arrow.
Display
CSS display. Defaults to Block (strict-CSS fidelity): flex layout, gap, and flex-direction only apply under Flex.
FocusKind
GradientKind
GridFlow
grid-auto-flow: how auto-placed items fill the implicit grid.
GridPlace
One endpoint of a grid-column / grid-row placement.
Justify
Main-axis distribution (justify-content).
Len
A CSS length. Percentages are stored as a fraction (0.0..=1.0); vh/vw hold the raw viewport-percentage number (e.g. 100vhVh(100.0)). rem is resolved to pixels at parse time.
Overflow
Overflow behaviour for content exceeding a box.
Paint
A drawable item in painter’s order (parents before children).
Position
position. Relative is the normal in-flow box (the default); Absolute takes the box out of flow and positions it by its inset against the nearest positioned ancestor.
TextAlign
Horizontal text alignment within a text box (text-align).
TextWrap
How a line may break when a word is wider than its box (overflow-wrap / word-break). CSS’s default lets a long word overflow rather than break.
Track
A grid track size (grid-template-columns/-rows).
TrackSide
One side of a minmax(), never itself a minmax. A Fr is only valid on the max side (a flex minimum is meaningless), and degrades to auto if used as a minimum.

Functions§

layout
Lay out root into an avail_w x avail_h viewport, returning paint items and hit regions. Text leaves are sized via measure.
layout_scrolled
Lay out with the shell’s current scroll offsets (one per scrollable box, in tree order). A missing entry is 0.

Type Aliases§

Corners
Corner radii in CSS order, top-left, top-right, bottom-right, bottom-left. A single border-radius fills all four; the per-corner longhands override.
Measure
Callback that measures a text block: (text, font_size, weight, wrap, max_width) -> (w, h). Measures a text node to (width, height) given an optional max width. Takes the whole TextContent so new text properties (family, spacing, style…) don’t each widen this signature.
Transform
A 2-D affine transform, as the six coefficients [a, b, c, d, e, f] (kurbo Affine order: x' = a·x + c·y + e, y' = b·x + d·y + f). Translations are in logical px; the origin is applied at paint time (CSS default: box centre).