pub struct Label { /* private fields */ }Expand description
A block of text laid out with one text style.
Build one with label. The label keeps the layout of its current text
and rebuilds it only when the text, the style or the offered width
changes, and keeps the glyph runs of that layout and rebuilds them only
when the layout, the node’s position or the resolved text color changes.
Trait Implementations§
Source§impl Widget for Label
impl Widget for Label
Source§fn semantics(&self) -> Option<Semantics>
fn semantics(&self) -> Option<Semantics>
Reports the text as the accessible value.
The role is what an accessibility backend maps a static text to, and such a node takes its name from its value there, so the text rides in the value and the label stays empty.
Source§fn measure(&mut self, input: MeasureInput) -> Option<Size>
fn measure(&mut self, input: MeasureInput) -> Option<Size>
Lays the text out against the offered width and returns its size.
A definite AvailableSpace::Definite wraps the text at that width,
and AvailableSpace::MaxContent lays it out on one line. An
AvailableSpace::MinContent request gets the text wrapped at every
opportunity, whose width is its longest unbreakable word, so a label
in a row too narrow for it can shrink and wrap instead of overflowing
and squeezing its siblings. A label capped to one line answers with
its ellipsis alone and one line of height, since it can cut any text
down to that. Under a cap of more lines, the min-content height stays
the full text’s, since it answers what the text needs rather than what
the cap shows; the line cap reports its height at a definite width.
The text is shaped once and kept; a call that offers another width than the last one re-breaks the shaped text’s lines, because the layout engine measures one node at several widths within a pass. The min-content answer breaks the same shaped text at every opportunity and then breaks it back at the width the label was last measured at, so once the label has been measured at one, the answer never changes the lines paint draws. The glyph runs are dropped whenever the shaped text or its line breaking changed, so paint rebuilds them from the lines the last call left.
§Panics
Panics under the conditions of TextSystem::with,
in particular when called from inside another with call on the same
thread.
Source§fn paint(&self, cx: &PaintCx<'_>, out: &mut Vec<PaintOp>)
fn paint(&self, cx: &PaintCx<'_>, out: &mut Vec<PaintOp>)
Appends one PaintOp::Glyphs per run of the current layout.
The runs are rebuilt when they were invalidated, when the node paints at another position, or when the resolved text color changed, because glyph positions and colors are baked into them. Each run carries the color the node’s text color or the label’s style resolves to under the current theme. When that color is a token, resolving it marks the node to repaint on a theme switch, and a literal color does not.
§Panics
Panics when the glyph runs are already borrowed on this thread, which the paint pass cannot do: it paints one node at a time and a widget never paints its own node again from inside the call.