Skip to main content

Module text_widget

Module text_widget 

Source
Expand description

TextWidget — a leaf widget that renders a localized text string.

TextWidget is the building block for every visible label in the framework. It delegates measurement and rasterization to the TextBackend and supports three overflow modes: [TextOverflow::Wrap] (default — grows vertically), [TextOverflow::Ellipsis] with trailing, middle, or leading truncation, and a minimal markup subset ([label](url), *italic*, **bold**) with per-link click/hover dispatch.

Text and color accept either static values or reactive Signal/Prop bindings. The default color role is [TextRole::Primary], resolved against the active theme at paint time, so theme switches update text color without any explicit binding or rebuild.

§Accessibility

A TextWidget is reviewable by default: it emits AccessKit text runs — one per visual line, with a position and an advance for every character — so a screen reader’s review cursor can walk it, a braille cell can be routed to the word under it, and AXBoundsForRange and its Windows and Linux equivalents can answer. Runs are excluded from object navigation by accesskit_consumer’s own filter, so they add no stops to anyone’s traversal and no targets to any hit test.

Geometry is always present: real when a text backend measured the label, and a zero-width box at its leading edge when none did. Never absent — Range::bounding_boxes() discards every box it has collected on the first run missing any of bounds, direction, positions or widths, so one geometry-less run would take the whole label’s geometry with it.

A label inside a control that owns the same accessible name must call a11y_hidden, or a reader hears the string twice. Standalone body text should not.

Single-line / ellipsis text opts into shrink by default: an over-constrained stack compresses the label down to the ellipsis-glyph width before the label overflows. Call no_shrink to restore rigid behavior, or min_shrink_width to set a custom floor. Wrap-mode text is height-variable and therefore always rigid; opt it into compression with Shrinkable.

// Single-line label that truncates with a trailing ellipsis if too narrow:
let _w = TextWidget::new(lit!("Save document")).single_line();

§Touch and pen

Inline links are reachable by a plain tap: the handler at on_tap follows the link run under the press with no modifier of any kind. (The touch inventory recorded this file as Ctrl-gated and therefore unreachable by touch; that gate was rich_text/mouse.rs’s — modifiers.command() || read_only, since widened to kind.is_direct() || read_only || command_held — and never existed here.) The hover cursor over a link run is a mouse and pen affordance and costs a finger nothing.

A link run is text-height and its size is constrained by the line height of the text around it, which is exactly WCAG 2.2 SC 2.5.8’s inline exception, so it is not raised to the 24 dp floor and is not reported as a target region.

Structs§

TextWidget