pub enum WidgetText {
    RichText(RichText),
    LayoutJob(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§

§

RichText(RichText)

§

LayoutJob(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 is_empty(&self) -> bool

source

pub fn text(&self) -> &str

source

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

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) -> Self

Set the TextStyle unless it has already been set

Prefer using RichText directly!

source

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

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

Prefer using RichText directly!

source

pub fn heading(self) -> Self

Prefer using RichText directly!

source

pub fn monospace(self) -> Self

Prefer using RichText directly!

source

pub fn code(self) -> Self

Prefer using RichText directly!

source

pub fn strong(self) -> Self

Prefer using RichText directly!

source

pub fn weak(self) -> Self

Prefer using RichText directly!

source

pub fn underline(self) -> Self

Prefer using RichText directly!

source

pub fn strikethrough(self) -> Self

Prefer using RichText directly!

source

pub fn italics(self) -> Self

Prefer using RichText directly!

source

pub fn small(self) -> Self

Prefer using RichText directly!

source

pub fn small_raised(self) -> Self

Prefer using RichText directly!

source

pub fn raised(self) -> Self

Prefer using RichText directly!

source

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

Prefer using RichText directly!

source

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

source

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

Layout with wrap mode based on the containing Ui.

wrap: override for Ui::wrap_text.

source

pub fn into_galley_impl( self, ctx: &Context, style: &Style, wrap: bool, available_width: f32, fallback_font: FontSelection, default_valign: Align ) -> Arc<Galley>

Trait Implementations§

source§

impl Clone for WidgetText

source§

fn clone(&self) -> WidgetText

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for WidgetText

source§

fn default() -> Self

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

impl From<&String> for WidgetText

source§

fn from(text: &String) -> Self

Converts to this type from the input type.
source§

impl From<&str> for WidgetText

source§

fn from(text: &str) -> Self

Converts to this type from the input type.
source§

impl From<Arc<Galley>> for WidgetText

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl From<LayoutJob> for WidgetText

source§

fn from(layout_job: LayoutJob) -> Self

Converts to this type from the input type.
source§

impl From<RichText> for WidgetText

source§

fn from(rich_text: RichText) -> Self

Converts to this type from the input type.
source§

impl From<String> for WidgetText

source§

fn from(text: String) -> Self

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<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> ToOwned for T
where T: Clone,

§

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

§

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

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