pub struct Label {
text: WidgetText,
wrap_mode: Option<TextWrapMode>,
sense: Option<Sense>,
selectable: Option<bool>,
}
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
.
Fields§
§text: WidgetText
§wrap_mode: Option<TextWrapMode>
§sense: Option<Sense>
§selectable: Option<bool>
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, Ui::wrap_mode
will be used, which can be overridden with 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 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() {
/* … */
}