Skip to main content

WidgetText

Enum WidgetText 

Source
pub enum WidgetText {
    Text(String),
    RichText(Arc<RichText>),
    LayoutJob(Arc<LayoutJob>),
    Galley(Arc<Galley>),
}
Expand description

This is how you specify text for a widget.

A lot of widgets use impl Into<WidgetText> as an argument, allowing you to pass in String, RichText, LayoutJob, and more.

Often a WidgetText is just a simple String, but it can be a RichText (text with color, style, etc), a LayoutJob (for when you want full control of how the text looks) or text that has already been laid out in a Galley.

You can color the text however you want, or use Color32::PLACEHOLDER which will be replaced with a color chosen by the widget that paints the text.

Variants§

§

Text(String)

Plain unstyled text.

We have this as a special case, as it is the common-case, and it uses less memory than Self::RichText.

§

RichText(Arc<RichText>)

Text and optional style choices for it.

Prefer Self::Text if there is no styling, as it will be faster.

§

LayoutJob(Arc<LayoutJob>)

Use this LayoutJob when laying out the text.

Only LayoutJob::text and LayoutJob::sections are guaranteed to be respected.

TextWrapping::max_width, LayoutJob::halign, LayoutJob::justify and LayoutJob::first_row_min_height will likely be determined by the crate::Layout of the Ui the widget is placed in. If you want all parts of the LayoutJob respected, then convert it to a Galley and use Self::Galley instead.

You can color the text however you want, or use Color32::PLACEHOLDER which will be replaced with a color chosen by the widget that paints the text.

§

Galley(Arc<Galley>)

Use exactly this galley when painting the text.

You can color the text however you want, or use Color32::PLACEHOLDER which will be replaced with a color chosen by the widget that paints the text.

Implementations§

Source§

impl WidgetText

Source

pub fn concat( ui: &Ui, parts: impl IntoIterator<Item = impl Into<RichText>>, ) -> WidgetText

Concatenate several differently styled pieces of text into a single WidgetText.

The pieces are laid out as one paragraph, without any spacing between them.

The style and vertical text alignment of ui is used for the pieces, so the result should be used in that same ui.

ui.label(WidgetText::concat(
    ui,
    [
        RichText::new("Normal, "),
        RichText::new("strong, ").strong(),
        RichText::new("and small").small(),
    ],
));

See also Self::concat_with_valign and RichText::append_to for more control over the resulting LayoutJob.

Source

pub fn concat_with_valign( style: &Style, valign: Align, parts: impl IntoIterator<Item = impl Into<RichText>>, ) -> WidgetText

Same as Self::concat, but with an explicit Style and vertical text alignment.

valign is how each piece is aligned against the others, and is usually Ui::text_valign.

Source

pub fn size(self, size: f32) -> WidgetText

Override the font size.

For Self::Galley, this does nothing because it has already been laid out.

Source

pub fn is_empty(&self) -> bool

Source

pub fn text(&self) -> &str

Source

pub fn text_style(self, text_style: TextStyle) -> WidgetText

Override the TextStyle if, and only if, this is a RichText.

Prefer using RichText directly!

Source

pub fn fallback_text_style(self, text_style: TextStyle) -> WidgetText

Set the TextStyle unless it has already been set

Prefer using RichText directly!

Source

pub fn color(self, color: impl Into<Color32>) -> WidgetText

Override text color if, and only if, this is a RichText.

Prefer using RichText directly!

Source

pub fn heading(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn monospace(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn code(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn strong(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn weak(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn underline(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn strikethrough(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn italics(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn small(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn small_raised(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn raised(self) -> WidgetText

Prefer using RichText directly!

Source

pub fn background_color( self, background_color: impl Into<Color32>, ) -> WidgetText

Prefer using RichText directly!

Source

pub fn into_layout_job( self, style: &Style, fallback_font: FontSelection, default_valign: Align, ) -> Arc<LayoutJob> ⓘ

Source

pub fn into_galley( self, ui: &Ui, wrap_mode: Option<TextWrapMode>, available_width: f32, fallback_font: impl Into<FontSelection>, ) -> Arc<Galley> ⓘ

Layout with wrap mode based on the containing Ui.

wrap_mode: override for Ui::wrap_mode

Source

pub fn into_galley_impl( self, ctx: &Context, style: &Style, text_wrapping: TextWrapping, fallback_font: FontSelection, default_valign: Align, ) -> Arc<Galley> ⓘ

Trait Implementations§

Source§

impl Clone for WidgetText

Source§

fn clone(&self) -> WidgetText

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WidgetText

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for WidgetText

Source§

fn default() -> WidgetText

Returns the “default value” for a type. Read more
Source§

impl From<&Box<str>> for WidgetText

Source§

fn from(text: &Box<str>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<&String> for WidgetText

Source§

fn from(text: &String) -> WidgetText

Converts to this type from the input type.
Source§

impl From<&str> for WidgetText

Source§

fn from(text: &str) -> WidgetText

Converts to this type from the input type.
Source§

impl From<Arc<Galley>> for WidgetText

Source§

fn from(galley: Arc<Galley>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<Arc<LayoutJob>> for WidgetText

Source§

fn from(layout_job: Arc<LayoutJob>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<Arc<RichText>> for WidgetText

Source§

fn from(rich_text: Arc<RichText>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<Box<str>> for WidgetText

Source§

fn from(text: Box<str>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<Cow<'_, str>> for WidgetText

Source§

fn from(text: Cow<'_, str>) -> WidgetText

Converts to this type from the input type.
Source§

impl From<LayoutJob> for WidgetText

Source§

fn from(layout_job: LayoutJob) -> WidgetText

Converts to this type from the input type.
Source§

impl From<RichText> for WidgetText

Source§

fn from(rich_text: RichText) -> WidgetText

Converts to this type from the input type.
Source§

impl From<String> for WidgetText

Source§

fn from(text: String) -> WidgetText

Converts to this type from the input type.

Auto Trait Implementations§

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<'a, T> AtomExt<'a> for T
where T: Into<Atom<'a>>,

Source§

fn atom_id(self, id: IdSalt) -> Atom<'a>

Set the IdSalt for custom rendering. Read more
Source§

fn atom_size(self, size: Vec2) -> Atom<'a>

Set the atom to a fixed size. Read more
Source§

fn atom_grow(self, grow: bool) -> Atom<'a>

Grow this atom to the available space. Read more
Source§

fn atom_shrink(self, shrink: bool) -> Atom<'a>

Shrink this atom if there isn’t enough space. Read more
Source§

fn atom_max_size(self, max_size: Vec2) -> Atom<'a>

Set the maximum size of this atom. Read more
Source§

fn atom_max_width(self, max_width: f32) -> Atom<'a>

Set the maximum width of this atom. Read more
Source§

fn atom_max_height(self, max_height: f32) -> Atom<'a>

Set the maximum height of this atom.
Source§

fn atom_align(self, align: Align2) -> Atom<'a>

Sets the emath::Align2 of a single atom within its available space. Read more
Source§

fn atom_max_height_font_size(self, ui: &Ui) -> Atom<'a>
where Self: Sized,

Set the max height of this atom to match the font size. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<'a, T> IntoAtoms<'a> for T
where T: Into<Atom<'a>>,

Source§

fn collect(self, atoms: &mut Atoms<'a>)

Source§

fn into_atoms(self) -> Atoms<'a>
where Self: Sized,

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more