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
Sourcepub fn concat(
ui: &Ui,
parts: impl IntoIterator<Item = impl Into<RichText>>,
) -> WidgetText
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.
Sourcepub fn concat_with_valign(
style: &Style,
valign: Align,
parts: impl IntoIterator<Item = impl Into<RichText>>,
) -> WidgetText
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.
Sourcepub fn size(self, size: f32) -> WidgetText
pub fn size(self, size: f32) -> WidgetText
Override the font size.
For Self::Galley, this does nothing because it has already been laid out.
pub fn is_empty(&self) -> bool
pub fn text(&self) -> &str
Sourcepub fn text_style(self, text_style: TextStyle) -> WidgetText
pub fn text_style(self, text_style: TextStyle) -> WidgetText
Sourcepub fn fallback_text_style(self, text_style: TextStyle) -> WidgetText
pub fn fallback_text_style(self, text_style: TextStyle) -> WidgetText
Sourcepub fn color(self, color: impl Into<Color32>) -> WidgetText
pub fn color(self, color: impl Into<Color32>) -> WidgetText
Sourcepub fn heading(self) -> WidgetText
pub fn heading(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn monospace(self) -> WidgetText
pub fn monospace(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn code(self) -> WidgetText
pub fn code(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn strong(self) -> WidgetText
pub fn strong(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn weak(self) -> WidgetText
pub fn weak(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn underline(self) -> WidgetText
pub fn underline(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn strikethrough(self) -> WidgetText
pub fn strikethrough(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn italics(self) -> WidgetText
pub fn italics(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn small(self) -> WidgetText
pub fn small(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn small_raised(self) -> WidgetText
pub fn small_raised(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn raised(self) -> WidgetText
pub fn raised(self) -> WidgetText
Prefer using RichText directly!
Sourcepub fn background_color(
self,
background_color: impl Into<Color32>,
) -> WidgetText
pub fn background_color( self, background_color: impl Into<Color32>, ) -> WidgetText
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 (const: unstable) · 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§fn default() -> WidgetText
fn default() -> WidgetText
Source§impl From<&String> for WidgetText
impl From<&String> for WidgetText
Source§fn from(text: &String) -> WidgetText
fn from(text: &String) -> WidgetText
Source§impl From<&str> for WidgetText
impl From<&str> for WidgetText
Source§fn from(text: &str) -> WidgetText
fn from(text: &str) -> WidgetText
Source§impl From<LayoutJob> for WidgetText
impl From<LayoutJob> for WidgetText
Source§fn from(layout_job: LayoutJob) -> WidgetText
fn from(layout_job: LayoutJob) -> WidgetText
Source§impl From<RichText> for WidgetText
impl From<RichText> for WidgetText
Source§fn from(rich_text: RichText) -> WidgetText
fn from(rich_text: RichText) -> WidgetText
Source§impl From<String> for WidgetText
impl From<String> for WidgetText
Source§fn from(text: String) -> WidgetText
fn from(text: String) -> WidgetText
Auto Trait Implementations§
impl Forget for WidgetText
impl Freeze for WidgetText
impl Move for WidgetText
impl RefUnwindSafe for WidgetText
impl Send for WidgetText
impl Sync for WidgetText
impl Unpin for WidgetText
impl UnsafeUnpin 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§fn atom_align(self, align: Align2) -> Atom<'a>
fn atom_align(self, align: Align2) -> Atom<'a>
emath::Align2 of a single atom within its available space. Read moreSource§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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