Skip to main content

Label

Struct Label 

Source
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

Source§

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>

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>)

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.

Source§

fn ime_area(&self) -> Option<Rect>

Returns the rectangle the input method should anchor to while this widget holds the keyboard focus, in the paint coordinates of Widget::paint. Read more

Auto Trait Implementations§

§

impl !Freeze for Label

§

impl !RefUnwindSafe for Label

§

impl !Send for Label

§

impl !Sync for Label

§

impl !UnwindSafe for Label

§

impl Forget for Label

§

impl Move for Label

§

impl Unpin for Label

§

impl UnsafeUnpin for Label

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.