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
impl WidgetText
pub fn is_empty(&self) -> bool
pub fn text(&self) -> &str
Sourcepub fn text_style(self, text_style: TextStyle) -> Self
pub fn text_style(self, text_style: TextStyle) -> Self
Sourcepub fn fallback_text_style(self, text_style: TextStyle) -> Self
pub fn fallback_text_style(self, text_style: TextStyle) -> Self
Sourcepub fn strikethrough(self) -> Self
pub fn strikethrough(self) -> Self
Prefer using RichText directly!
Sourcepub fn small_raised(self) -> Self
pub fn small_raised(self) -> Self
Prefer using RichText directly!
Sourcepub fn background_color(self, background_color: impl Into<Color32>) -> Self
pub fn background_color(self, background_color: impl Into<Color32>) -> Self
Prefer using RichText directly!
pub fn into_layout_job( self, style: &Style, fallback_font: FontSelection, default_valign: Align, ) -> Arc<LayoutJob>
Sourcepub fn into_galley(
self,
ui: &Ui,
wrap_mode: Option<TextWrapMode>,
available_width: f32,
fallback_font: impl Into<FontSelection>,
) -> Arc<Galley>
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
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
impl Clone for WidgetText
Source§fn clone(&self) -> WidgetText
fn clone(&self) -> WidgetText
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WidgetText
impl Debug for WidgetText
Source§impl Default for WidgetText
impl Default for WidgetText
Source§impl From<&String> for WidgetText
impl From<&String> for WidgetText
Source§impl From<&str> for WidgetText
impl From<&str> for WidgetText
Source§impl From<LayoutJob> for WidgetText
impl From<LayoutJob> for WidgetText
Source§impl From<RichText> for WidgetText
impl From<RichText> for WidgetText
Auto Trait Implementations§
impl Freeze for WidgetText
impl RefUnwindSafe for WidgetText
impl Send for WidgetText
impl Sync for WidgetText
impl Unpin for WidgetText
impl UnwindSafe for WidgetText
Blanket Implementations§
Source§impl<'a, T> AtomExt<'a> for T
impl<'a, T> AtomExt<'a> for T
Source§fn atom_shrink(self, shrink: bool) -> Atom<'a>
fn atom_shrink(self, shrink: bool) -> Atom<'a>
Source§fn atom_max_size(self, max_size: Vec2) -> Atom<'a>
fn atom_max_size(self, max_size: Vec2) -> Atom<'a>
Source§fn atom_max_width(self, max_width: f32) -> Atom<'a>
fn atom_max_width(self, max_width: f32) -> Atom<'a>
Source§fn atom_max_height(self, max_height: f32) -> Atom<'a>
fn atom_max_height(self, max_height: f32) -> Atom<'a>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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