pub struct Label { /* private fields */ }Expand description
Static text.
Usually it is more convenient to use Ui::label.
ui.label("Equivalent");
ui.add(egui::Label::new("Equivalent"));
ui.add(egui::Label::new("With Options").wrap(false));
ui.label(egui::RichText::new("With formatting").underline());For full control of the text you can use crate::text::LayoutJob
as argument to Self::new.
Implementations§
source§impl Label
impl Label
pub fn new(text: impl Into<WidgetText>) -> Self
pub fn text(&self) -> &str
sourcepub fn wrap(self, wrap: bool) -> Self
pub fn wrap(self, wrap: bool) -> Self
If true, the text will wrap to stay within the max width of the Ui.
Calling wrap will override Self::truncate.
By default Self::wrap will be true in vertical layouts
and horizontal layouts with wrapping,
and false on non-wrapping horizontal layouts.
Note that any \n in the text will always produce a new line.
You can also use crate::Style::wrap.
sourcepub fn truncate(self, truncate: bool) -> Self
pub fn truncate(self, truncate: bool) -> Self
If true, the text will stop at the max width of the Ui,
and what doesn’t fit will be elided, replaced with ….
If the text is truncated, the full text will be shown on hover as a tool-tip.
Default is false, which means the text will expand the parent Ui,
or wrap if Self::wrap is set.
Calling truncate will override Self::wrap.
sourcepub fn sense(self, sense: Sense) -> Self
pub fn sense(self, sense: Sense) -> Self
Make the label respond to clicks and/or drags.
By default, a label is inert and does not respond to click or drags. By calling this you can turn the label into a button of sorts. This will also give the label the hover-effect of a button, but without the frame.
if ui.add(Label::new("click me").sense(Sense::click())).clicked() {
/* … */
}source§impl Label
impl Label
sourcepub fn layout_in_ui(self, ui: &mut Ui) -> (Pos2, WidgetTextGalley, Response)
pub fn layout_in_ui(self, ui: &mut Ui) -> (Pos2, WidgetTextGalley, Response)
Do layout and position the galley in the ui, without painting it or adding widget info.