Skip to main content

TextStyle

Struct TextStyle 

Source
pub struct TextStyle {
    pub font_size: f32,
    pub paint: Paint,
    pub shadow: Option<Shadow>,
    pub weight: u16,
    pub italic: bool,
    pub align: TextAlign,
    pub max_lines: Option<u16>,
    pub ellipsis: bool,
    pub line_height: Option<f32>,
    pub letter_spacing: f32,
    pub raster: GlyphRaster,
    pub no_wrap: bool,
}

Fields§

§font_size: f32§paint: Paint§shadow: Option<Shadow>§weight: u16

OpenType weight axis: 400 is normal, 700 is bold. Selects the matching font face.

§italic: bool§align: TextAlign§max_lines: Option<u16>

Clamp the text to at most this many lines (None = unlimited). Lines beyond it are dropped.

§ellipsis: bool

When clamped by max_lines, replace the overflowing tail with an ellipsis ().

§line_height: Option<f32>

Line height as a multiple of font_size (e.g. 1.5). None keeps the shaper’s natural line height, so the default renders byte-for-byte as before.

§letter_spacing: f32

Extra advance in logical pixels added after each glyph. 0.0 uses the font’s natural advances.

§raster: GlyphRaster

Which grid the glyphs land on. See GlyphRaster.

§no_wrap: bool

Keep the text on one line whatever width it is given, instead of wrapping into the box.

What a label in a toolbar, a status bar or a table cell wants: it is a name, and a name broken across two lines to fit a column reads as two things. Wrapping is the right default for prose and the wrong one for everything that is really a token, so it is a property of the style rather than of the box — the same text is a label in one place and a paragraph in another.

Implementations§

Source§

impl TextStyle

Source

pub fn new(font_size: f32, paint: impl Into<Paint>) -> Self

Source

pub fn with_no_wrap(self, no_wrap: bool) -> Self

Keeps the text on one line; see no_wrap.

Source

pub fn with_weight(self, weight: u16) -> Self

Source

pub fn with_shadow(self, shadow: Shadow) -> Self

Drops a shadow behind the glyphs — what keeps text legible over an image the style knows nothing about.

Source

pub fn with_italic(self, italic: bool) -> Self

Source

pub fn with_align(self, align: TextAlign) -> Self

Source

pub fn with_max_lines(self, max_lines: u16) -> Self

Source

pub fn with_ellipsis(self, ellipsis: bool) -> Self

Source

pub fn with_line_height(self, line_height: f32) -> Self

Source

pub fn with_letter_spacing(self, letter_spacing: f32) -> Self

Source

pub fn with_raster(self, raster: GlyphRaster) -> Self

Puts the glyphs on whole pixels with coverage resolved to on or off. See GlyphRaster.

Trait Implementations§

Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> TextStyle

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 Copy for TextStyle

Source§

impl Debug for TextStyle

Source§

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

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

impl PartialEq for TextStyle

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Scale for TextStyle

Source§

fn scale(self, sf: f32) -> Self

Source§

impl StructuralPartialEq for TextStyle

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

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