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").truncate());
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_mode(self, wrap_mode: TextWrapMode) -> Self
pub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Self
Set the wrap mode for the text.
By default, crate::Ui::wrap_mode
will be used, which can be overridden with crate::Style::wrap_mode
.
Note that any \n
in the text will always produce a new line.
Sourcepub fn wrap(self) -> Self
pub fn wrap(self) -> Self
Set Self::wrap_mode
to TextWrapMode::Wrap
.
Sourcepub fn extend(self) -> Self
pub fn extend(self) -> Self
Set Self::wrap_mode
to TextWrapMode::Extend
,
disabling wrapping and truncating, and instead expanding the parent Ui
.
Sourcepub fn halign(self, align: Align) -> Self
pub fn halign(self, align: Align) -> Self
Sets the horizontal alignment of the Label to the given Align
value.
Sourcepub fn selectable(self, selectable: bool) -> Self
pub fn selectable(self, selectable: bool) -> Self
Can the user select the text with the mouse?
Overrides crate::style::Interaction::selectable_labels
.
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() {
/* … */
}