pub struct Label {
pub buffered: bool,
/* private fields */
}Expand description
A non-interactive text widget.
Used directly as a standalone label, and as a child of composite widgets
such as [Button] and (in the future) Checkbox, RadioGroup, etc.
When no explicit color is set via with_color, the
label reads its text color from the active Visuals
at paint time (ctx.visuals().text_color), so it automatically adapts to
dark / light mode switches.
Fields§
§buffered: boolWhen true (the default), this Label owns a CPU backbuffer
that’s re-rasterised on dirty and blitted every frame. Set to
false only for text that changes every frame (e.g. live
counters) where caching adds overhead with no benefit — those
go through ctx.fill_text direct every paint.
Implementations§
Source§impl Label
impl Label
pub fn new(text: impl Into<String>, font: Arc<Font>) -> Self
pub fn with_font_size(self, size: f64) -> Self
Sourcepub fn with_color(self, color: Color) -> Self
pub fn with_color(self, color: Color) -> Self
Override the label colour. Pass an explicit Color to always use that
colour regardless of the active theme. Omit this call to follow the
theme’s text_color automatically.
pub fn with_align(self, align: LabelAlign) -> Self
pub fn with_has_backbuffer(self, v: bool) -> Self
Sourcepub fn with_wrap(self, wrap: bool) -> Self
pub fn with_wrap(self, wrap: bool) -> Self
Enable or disable word-wrapping. When true, long lines are broken at
word boundaries to fit the available width; the label height expands to
accommodate all lines. Newlines in the text are always honoured.
Sourcepub fn with_lcd(self, pref: Option<bool>) -> Self
pub fn with_lcd(self, pref: Option<bool>) -> Self
Opt OUT of the system-wide font override for this Label. The
Label will render with self.font (passed to Label::new)
regardless of what font_settings::set_system_font is pointing
at. Useful for font-preview UI — each entry in a font picker
dropdown needs its OWN face, not the currently selected one.
Pin this label’s LCD setting: Some(true) always LCD, Some(false)
always grayscale, None (default) defers to the global toggle.
pub fn with_ignore_system_font(self, ignore: bool) -> Self
pub fn with_margin(self, m: Insets) -> Self
pub fn with_h_anchor(self, h: HAnchor) -> Self
pub fn with_v_anchor(self, v: VAnchor) -> Self
pub fn with_min_size(self, s: Size) -> Self
pub fn with_max_size(self, s: Size) -> Self
pub fn set_font_size(&mut self, size: f64)
pub fn set_text(&mut self, text: impl Into<String>)
pub fn set_color(&mut self, color: Color)
pub fn clear_color(&mut self)
pub fn set_align(&mut self, align: LabelAlign)
Trait Implementations§
Source§impl Widget for Label
impl Widget for Label
Source§fn hit_test(&self, _: Point) -> bool
fn hit_test(&self, _: Point) -> bool
Labels are never independently hittable. This lets their interactive parent (e.g., Button) retain full hit-test and focus ownership even when the label fills the parent’s entire bounds.
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Source§fn set_bounds(&mut self, b: Rect)
fn set_bounds(&mut self, b: Rect)
Source§fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
Source§fn lcd_preference(&self) -> Option<bool>
fn lcd_preference(&self) -> Option<bool>
Source§fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
Source§fn backbuffer_mode(&self) -> BackbufferMode
fn backbuffer_mode(&self) -> BackbufferMode
backbuffer_cache_mut] returns Some. Default
BackbufferMode::Rgba — correct for any widget.
Opt into BackbufferMode::LcdCoverage only when the widget
paints opaque content covering its full bounds.Source§fn layout(&mut self, available: Size) -> Size
fn layout(&mut self, available: Size) -> Size
Source§fn paint(&mut self, ctx: &mut dyn DrawCtx)
fn paint(&mut self, ctx: &mut dyn DrawCtx)
ctx. Read moreSource§fn h_anchor(&self) -> HAnchor
fn h_anchor(&self) -> HAnchor
HAnchor::FIT (take natural content width).Source§fn v_anchor(&self) -> VAnchor
fn v_anchor(&self) -> VAnchor
VAnchor::FIT (take natural content height).Source§fn on_event(&mut self, _: &Event) -> EventResult
fn on_event(&mut self, _: &Event) -> EventResult
EventResult::Consumed to stop bubbling.Source§fn properties(&self) -> Vec<(&'static str, String)>
fn properties(&self) -> Vec<(&'static str, String)>
Source§fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
true, hit_test_subtree stops recursing into this widget’s
children and returns this widget as the hit target. Used for floating
overlays (e.g. a scrollbar painted above its content) that must claim
the pointer before children that happen to share the same pixels.
Default: false.Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn id(&self) -> Option<&str>
fn id(&self) -> Option<&str>
Source§fn is_visible(&self) -> bool
fn is_visible(&self) -> bool
false to suppress painting this widget and all its children.
The widget’s own paint() will not be called. Default: true.Source§fn has_backbuffer(&self) -> bool
fn has_backbuffer(&self) -> bool
Source§fn contributes_children_to_inspector(&self) -> bool
fn contributes_children_to_inspector(&self) -> bool
Source§fn show_in_inspector(&self) -> bool
fn show_in_inspector(&self) -> bool
false to hide this widget (and its subtree) from the inspector
node snapshot entirely. Intended for zero-size utility widgets such
as layout-time watchers / tickers / invisible composers — they bloat
the inspector tree without providing user-relevant information and,
at scale, can make the inspector’s per-frame tree rebuild expensive.Source§fn paint_overlay(&mut self, _ctx: &mut dyn DrawCtx)
fn paint_overlay(&mut self, _ctx: &mut dyn DrawCtx)
Source§fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
paint_subtree applies this clip before recursing into
children, then restores the previous clip state afterward. The clip does
not affect paint_overlay, which runs after the clip is removed. Read moreSource§fn enforce_integer_bounds(&self) -> bool
fn enforce_integer_bounds(&self) -> bool
paint_subtree should snap this widget’s incoming
translation to the physical pixel grid. Read moreSource§fn take_raise_request(&mut self) -> bool
fn take_raise_request(&mut self) -> bool
crate::widgets::Stack) call this on each
child at the start of layout(). A widget that returns true is
moved to the END of its parent’s child list — painted last, i.e.
raised to the top of the z-order. take_ semantics: the call is
also expected to clear the request so the child doesn’t keep
getting raised every frame. Read moreSource§fn needs_paint(&self) -> bool
fn needs_paint(&self) -> bool
true if this widget, or any visible descendant, has state
that requires a repaint (hover change, tween in flight, etc.). Read moreSource§fn next_paint_deadline(&self) -> Option<Instant>
fn next_paint_deadline(&self) -> Option<Instant>
None = no scheduled wake.
The host loop turns a Some(t) into ControlFlow::WaitUntil(t) so
e.g. a cursor blink fires without continuous polling. Read more