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: f32Additional 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: TextScalingWhat size is relative to, and so whether the renderer’s
accessibility text scale still applies to it.
kind: TextKindWhat the text is; resolved to OpenType features against each face it is set in.
ground: TextGroundThe ground the text is set on, for the optical cut it is set in.
distinguish: boolSet 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
impl TextStyle
pub fn new(size: f32) -> 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
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
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
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
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
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
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
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
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
impl TextStyle
pub fn strong(self) -> 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
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
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 StructuralPartialEq for TextStyle
Auto Trait Implementations§
impl Freeze for TextStyle
impl !RefUnwindSafe for TextStyle
impl Send for TextStyle
impl Sync for TextStyle
impl Unpin for TextStyle
impl UnsafeUnpin for TextStyle
impl !UnwindSafe for TextStyle
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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