Struct egui::widgets::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").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

source

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

source

pub fn text(&self) -> &str

source

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.

source

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.

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