Skip to main content

RichText

Struct RichText 

Source
pub struct RichText { /* private fields */ }
Expand description

Text and optional style choices for it.

The style choices (font, color) are applied to the entire text. For more detailed control, use crate::text::LayoutJob instead.

A RichText can be used in most widgets and helper functions, e.g. Ui::label and Ui::button.

§Example

use egui::{RichText, Color32};

RichText::new("Plain");
RichText::new("colored").color(Color32::RED);
RichText::new("Large and underlined").size(20.0).underline();

Implementations§

Source§

impl RichText

Source

pub fn new(text: impl Into<String>) -> RichText

Source

pub fn is_empty(&self) -> bool

Source

pub fn text(&self) -> &str

Source

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

Select the font size (in points). This overrides the value from Self::text_style.

Source

pub fn extra_letter_spacing(self, extra_letter_spacing: f32) -> RichText

Extra spacing between letters, in points.

Default: 0.0.

For even text it is recommended you round this to an even number of pixels, e.g. using emath::GuiRounding.

Source

pub fn line_height(self, line_height: Option<f32>) -> RichText

Explicit line height of the text in points.

This is the distance between the bottom row of two subsequent lines of text.

If None (the default), the line height is determined by the font.

For even text it is recommended you round this to an even number of pixels, e.g. using emath::GuiRounding.

Source

pub fn family(self, family: FontFamily) -> RichText

Select the font family.

This overrides the value from Self::text_style.

Only the families available in crate::FontDefinitions::families may be used.

Source

pub fn font(self, font_id: FontId) -> RichText

Select the font and size. This overrides the value from Self::text_style.

Source

pub fn variation(self, tag: impl IntoTag, coord: f32) -> RichText

Add a variation coordinate.

Source

pub fn variations<T>( self, variations: impl IntoIterator<Item = (T, f32)>, ) -> RichText
where T: IntoTag,

Override the variation coordinates completely.

Source

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

Override the TextStyle.

Source

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

Set the TextStyle unless it has already been set

Source

pub fn heading(self) -> RichText

Source

pub fn monospace(self) -> RichText

Source

pub fn code(self) -> RichText

Monospace label with different background color.

Source

pub fn strong(self) -> RichText

Extra strong text (stronger color).

Source

pub fn weak(self) -> RichText

Extra weak text (fainter color).

Source

pub fn underline(self) -> RichText

Draw a line under the text.

If you want to control the line color, use LayoutJob instead.

Source

pub fn strikethrough(self) -> RichText

Draw a line through the text, crossing it out.

If you want to control the strikethrough line color, use LayoutJob instead.

Source

pub fn italics(self) -> RichText

Tilt the characters to the right.

Source

pub fn small(self) -> RichText

Smaller text.

Source

pub fn small_raised(self) -> RichText

For e.g. exponents.

Source

pub fn raised(self) -> RichText

Align text to top. Only applicable together with Self::small().

Source

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

Fill-color behind the text.

Source

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

Override text color.

If not set, Color32::PLACEHOLDER will be used, which will be replaced with a color chosen by the widget that paints the text.

Source

pub fn color_override(&self) -> Option<Color32>

The explicit text color set by Self::color, if any.

This does not resolve colors from Self::strong, Self::weak, the style, or the widget that paints the text.

use egui::{Color32, RichText};

let text = RichText::new("Hello");
assert_eq!(text.color_override(), None);
assert_eq!(text.color_override().unwrap_or(Color32::WHITE), Color32::WHITE);

let text = text.color(Color32::RED);
assert_eq!(text.color_override(), Some(Color32::RED));
Source

pub fn font_height(&self, fonts: &mut FontsView<'_>, style: &Style) -> f32

Read the font height of the selected text style.

Returns a value rounded to emath::GUI_ROUNDING.

Source

pub fn append_to( self, layout_job: &mut LayoutJob, style: &Style, fallback_font: FontSelection, default_valign: Align, )

Append to an existing LayoutJob

Note that the color of the RichText must be set, or may default to an undesirable color.

§Example
use egui::{Style, RichText, text::LayoutJob, Color32, FontSelection, Align};

let style = Style::default();
let mut layout_job = LayoutJob::default();
RichText::new("Normal")
    .color(style.visuals.text_color())
    .append_to(
        &mut layout_job,
        &style,
        FontSelection::Default,
        Align::Center,
    );
RichText::new("Large and underlined")
    .color(style.visuals.text_color())
    .size(20.0)
    .underline()
    .append_to(
        &mut layout_job,
        &style,
        FontSelection::Default,
        Align::Center,
    );

Trait Implementations§

Source§

impl Clone for RichText

Source§

fn clone(&self) -> RichText

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 RichText

Source§

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

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

impl Default for RichText

Source§

fn default() -> RichText

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

impl From<&Box<str>> for RichText

Source§

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

Converts to this type from the input type.
Source§

impl From<&String> for RichText

Source§

fn from(text: &String) -> RichText

Converts to this type from the input type.
Source§

impl From<&mut Box<str>> for RichText

Source§

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

Converts to this type from the input type.
Source§

impl From<&mut String> for RichText

Source§

fn from(text: &mut String) -> RichText

Converts to this type from the input type.
Source§

impl From<&str> for RichText

Source§

fn from(text: &str) -> RichText

Converts to this type from the input type.
Source§

impl From<Box<str>> for RichText

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

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 RichText

Source§

fn from(text: String) -> RichText

Converts to this type from the input type.
Source§

impl PartialEq for RichText

Source§

fn eq(&self, other: &RichText) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RichText

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