pub struct DrawTextStyle {
pub font_family: Option<String>,
pub font_size: f32,
pub font_weight: FontWeight,
pub font_style: FontStyle,
pub letter_spacing: f32,
pub line_height: Option<f32>,
pub line_height_style: Option<LineHeightStyle>,
pub align: TextAlign,
pub vertical_align: TextVerticalAlign,
}Expand description
Everything crate::DrawScope needs to measure and draw a run of text.
A style is a plain value: sizes are already in scope (logical) units, and
every field is resolved — there is no inheritance or theme lookup at draw
time. Build one once and reuse it; measurement is cached on the
(text, style) pair, so a style rebuilt with identical values still hits
the cache.
Fields§
§font_family: Option<String>Family name to resolve against the fonts the app registered. None
asks for the framework’s default family.
Only named families resolve: file-backed families are loaded by the app at startup and looked up by the name in their font tables.
font_size: f32Size of the text, in scope units. A non-positive or non-finite value uses
DEFAULT_FONT_SIZE.
font_weight: FontWeightWeight of the face, from 1 to 1000.
font_style: FontStyleNormal or italic face.
letter_spacing: f32Extra advance inserted between characters, in scope units.
line_height: Option<f32>Distance between consecutive baselines. None uses the font’s natural
line height.
line_height_style: Option<LineHeightStyle>How the line sits inside that height. None takes
LineHeightStyle::default, as a composed Text does.
align: TextAlignHow the text block is placed horizontally inside its box.
vertical_align: TextVerticalAlignHow the text block is placed vertically inside its box.
Implementations§
Source§impl DrawTextStyle
impl DrawTextStyle
Sourcepub const DEFAULT_FONT_SIZE: f32 = 14.0
pub const DEFAULT_FONT_SIZE: f32 = 14.0
The size used when a style carries a non-positive or non-finite one. Matches the framework-wide text default.
Sourcepub fn new(font_size: f32) -> DrawTextStyle
pub fn new(font_size: f32) -> DrawTextStyle
Creates a style with the given font size, in scope units, and defaults for every other field.
Sourcepub fn with_font_family(self, family: impl Into<String>) -> DrawTextStyle
pub fn with_font_family(self, family: impl Into<String>) -> DrawTextStyle
Sets the font family by name. An empty name selects the framework default family.
Sourcepub fn with_font_size(self, font_size: f32) -> DrawTextStyle
pub fn with_font_size(self, font_size: f32) -> DrawTextStyle
Sets the font size, in scope units.
Sourcepub fn with_weight(self, weight: FontWeight) -> DrawTextStyle
pub fn with_weight(self, weight: FontWeight) -> DrawTextStyle
Sets the font weight.
Sourcepub fn with_style(self, style: FontStyle) -> DrawTextStyle
pub fn with_style(self, style: FontStyle) -> DrawTextStyle
Sets the font style.
Sourcepub fn with_letter_spacing(self, letter_spacing: f32) -> DrawTextStyle
pub fn with_letter_spacing(self, letter_spacing: f32) -> DrawTextStyle
Sets the extra advance between characters, in scope units.
Sourcepub fn with_line_height(self, line_height: f32) -> DrawTextStyle
pub fn with_line_height(self, line_height: f32) -> DrawTextStyle
Sets the distance between baselines, in scope units. A non-finite value clears it.
Sourcepub fn with_line_height_style(
self,
line_height_style: LineHeightStyle,
) -> DrawTextStyle
pub fn with_line_height_style( self, line_height_style: LineHeightStyle, ) -> DrawTextStyle
Asks for a line-height policy other than the default one.
Sourcepub fn with_align(self, align: TextAlign) -> DrawTextStyle
pub fn with_align(self, align: TextAlign) -> DrawTextStyle
Sets how the text block is placed horizontally inside its box.
Sourcepub fn with_vertical_align(
self,
vertical_align: TextVerticalAlign,
) -> DrawTextStyle
pub fn with_vertical_align( self, vertical_align: TextVerticalAlign, ) -> DrawTextStyle
Sets how the text block is placed vertically inside its box.
Sourcepub fn resolved_font_size(&self) -> f32
pub fn resolved_font_size(&self) -> f32
The font size a measurer/rasterizer will actually use. Non-finite and
non-positive sizes fall back to DrawTextStyle::DEFAULT_FONT_SIZE instead
of producing NaN geometry.
Sourcepub fn resolved_letter_spacing(&self) -> f32
pub fn resolved_letter_spacing(&self) -> f32
The letter spacing a measurer will actually use.
Sourcepub fn resolved_line_height(&self, natural: f32) -> f32
pub fn resolved_line_height(&self, natural: f32) -> f32
The line height a measurer will actually use, given the font’s natural
one. natural is only consulted when the style leaves it unset.
Trait Implementations§
Source§impl Clone for DrawTextStyle
impl Clone for DrawTextStyle
Source§fn clone(&self) -> DrawTextStyle
fn clone(&self) -> DrawTextStyle
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 DrawTextStyle
impl Debug for DrawTextStyle
Source§impl Default for DrawTextStyle
impl Default for DrawTextStyle
Source§fn default() -> DrawTextStyle
fn default() -> DrawTextStyle
Source§impl PartialEq for DrawTextStyle
impl PartialEq for DrawTextStyle
impl StructuralPartialEq for DrawTextStyle
Auto Trait Implementations§
impl Forget for DrawTextStyle
impl Freeze for DrawTextStyle
impl Move for DrawTextStyle
impl RefUnwindSafe for DrawTextStyle
impl Send for DrawTextStyle
impl Sync for DrawTextStyle
impl Unpin for DrawTextStyle
impl UnsafeUnpin for DrawTextStyle
impl UnwindSafe for DrawTextStyle
Blanket Implementations§
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> ErasedDestructor for Twhere
T: 'static,
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