egui::widgets

Struct Label

Source
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

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

Source§

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

Source§

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.