Struct egui::widgets::Label

source ·
pub struct Label {
    text: WidgetText,
    wrap_mode: Option<TextWrapMode>,
    sense: Option<Sense>,
    selectable: Option<bool>,
    halign: Option<Align>,
}
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>§halign: Option<Align>

Implementations§

source§

impl Label

source

pub fn new(text: impl Into<WidgetText>) -> Self

source

pub fn text(&self) -> &str

source

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.

source

pub fn wrap(self) -> Self

source

pub fn truncate(self) -> Self

source

pub fn extend(self) -> Self

Set Self::wrap_mode to TextWrapMode::Extend, disabling wrapping and truncating, and instead expanding the parent Ui.

source

pub fn halign(self, align: Align) -> Self

Sets the horizontal alignment of the Label to the given Align value.

source

pub fn selectable(self, selectable: bool) -> Self

Can the user select the text with the mouse?

Overrides crate::style::Interaction::selectable_labels.

source

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

source

pub fn layout_in_ui(self, ui: &mut Ui) -> (Pos2, Arc<Galley>, Response)

Do layout and position the galley in the ui, without painting it or adding widget info.

Trait Implementations§

source§

impl Widget for Label

source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl Freeze for Label

§

impl RefUnwindSafe for Label

§

impl Send for Label

§

impl Sync for Label

§

impl Unpin for Label

§

impl UnwindSafe 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> 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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.