Skip to main content

TextStyle

Struct TextStyle 

pub struct TextStyle {
Show 18 fields pub size: f32, pub line_height: f32, pub weight: TextWeight, pub italic: bool, pub family: FontChoice, pub hyphenation: Hyphenation, pub letter_spacing: f32, pub font_features: Vec<OpenTypeFeature>, pub font_variations: Vec<FontVariation>, pub optical_sizing: OpticalSizing, pub align: ParagraphAlign, pub wrap_mode: TextWrapMode, pub hanging_punctuation: HangingPunctuation, pub fragmentation: Fragmentation, pub scaling: TextScaling, pub kind: TextKind, pub ground: TextGround, pub distinguish: bool,
}
Expand description

The complete typographic style for a plain text run.

Keeping these values together is more than API convenience: measurement, wrapping, glyph placement, and painting must all receive the exact same metrics or text will clip, jump, or wrap differently between layout and draw. line_height is a multiplier, matching CSS and the values in the theme’s typography tokens.

Fields§

§size: f32§line_height: f32§weight: TextWeight§italic: bool§family: FontChoice§hyphenation: Hyphenation§letter_spacing: f32

Additional advance in logical pixels between shaped clusters.

§font_features: Vec<OpenTypeFeature>§font_variations: Vec<FontVariation>§optical_sizing: OpticalSizing§align: ParagraphAlign§wrap_mode: TextWrapMode§hanging_punctuation: HangingPunctuation§fragmentation: Fragmentation§scaling: TextScaling

What size is relative to, and so whether the renderer’s accessibility text scale still applies to it.

§kind: TextKind

What the text is; resolved to OpenType features against each face it is set in.

§ground: TextGround

The ground the text is set on, for the optical cut it is set in.

§distinguish: bool

Set every look-alike (I, l, 1 and 0, O) apart whatever the kind: text on a security surface (Self::on_security_surface). The renderer also sets it on all text while the person’s “Always distinguish similar letters” setting is on.

Implementations§

§

impl TextStyle

pub fn new(size: f32) -> TextStyle

Construct regular sans-serif text at a renderer-relative base size (TextScaling::Renderer) with the renderer’s legacy leading. UI text takes a role instead: crate::theme::Theme::text.

pub fn content(size: f32) -> TextStyle

Document-space text at exactly size (TextScaling::Content): zoomed canvases, PDF stamps, terminal grids. The accessibility text scale never applies; the content’s zoom does, through the transform.

pub fn with_line_height(self, multiplier: f32) -> TextStyle

pub fn with_weight(self, weight: TextWeight) -> TextStyle

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

pub fn with_family(self, family: FontChoice) -> TextStyle

pub fn with_letter_spacing(self, px: f32) -> TextStyle

Set CSS-like letter spacing in logical pixels.

pub fn with_tracking(self, em: f32) -> TextStyle

Set tracking in em units, converted using this style’s font size.

pub fn with_kind(self, kind: TextKind) -> TextStyle

Say what the text is (TextKind). Code also sets it in the mono face. Numeric and Secret decide the figures, so they replace any figure style set before them (the Reading role’s old-style figures).

pub fn with_ground(self, ground: TextGround) -> TextStyle

Say what ground the text is set on (TextGround). Theme roles carry their theme’s; a surface that paints its own ground sets it.

pub fn on_security_surface(self) -> TextStyle

Text on a security surface — a permission prompt, a link preview, an invite or join confirmation, identity verification — where every look-alike letter and figure is set apart, prose included. Toolkit surfaces of these kinds mark themselves; a custom-painted one marks its styles here.

pub fn with_font_feature(self, tag: OpenTypeTag, value: u32) -> TextStyle

pub fn with_kerning(self, enabled: bool) -> TextStyle

pub fn with_discretionary_ligatures(self, enabled: bool) -> TextStyle

pub fn with_small_caps(self, enabled: bool) -> TextStyle

pub fn with_numeric_style(self, style: NumericStyle) -> TextStyle

pub fn with_font_variation(self, tag: OpenTypeTag, value: f32) -> TextStyle

pub fn with_optical_sizing(self, optical_sizing: OpticalSizing) -> TextStyle

pub fn with_align(self, align: ParagraphAlign) -> TextStyle

pub fn with_wrap_mode(self, wrap_mode: TextWrapMode) -> TextStyle

pub fn with_hanging_punctuation(self, hanging: HangingPunctuation) -> TextStyle

pub fn with_fragmentation(self, orphans: u8, widows: u8) -> TextStyle

pub fn with_auto_hyphenation(self, language: impl Into<String>) -> TextStyle

Opt this paragraph into automatic language-aware hyphenation.

language is a BCP-47 tag such as "en-US", "de", or "pt-BR". Unknown or malformed tags fall back to normal word wrapping, so content remains readable when no compiled pattern matches.

pub fn with_hyphenator(self, hyphenator: Arc<dyn Hyphenator>) -> TextStyle

Use a custom discretionary-break algorithm. The same policy is used for measurement and painting, and participates in cache identity.

pub fn line_height_px(&self) -> f32

§

impl TextStyle

pub fn strong(self) -> TextStyle

The next emphasis weight: regular and medium text become semibold, semibold becomes bold. Use it for emphasis inside a role (Body.strong() for a name in a row) instead of picking a weight.

pub fn numeric(self) -> TextStyle

Numbers that line up in a column or change in place (TextKind::Numeric): tabular figures where the face has them.

pub fn with_content_size(self, px: f32) -> TextStyle

This style’s face, weight and leading at exactly px, as content (TextScaling::Content): type sized by the thing it sits in — the initials in an avatar disc, a label on a zoomed canvas — rather than by the reader’s text scale.

Trait Implementations§

§

impl Clone for TextStyle

§

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
§

impl Debug for TextStyle

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for TextStyle

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Fruit for T
where T: Send + Downcast,

§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T

§

impl<T> WasmNotSync for T
where T: Sync,