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: u16OpenType 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: boolWhen 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: f32Extra advance in logical pixels added after each glyph. 0.0 uses the font’s natural advances.
raster: GlyphRasterWhich grid the glyphs land on. See GlyphRaster.
no_wrap: boolKeep 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
impl TextStyle
pub fn new(font_size: f32, paint: impl Into<Paint>) -> Self
Sourcepub fn with_no_wrap(self, no_wrap: bool) -> Self
pub fn with_no_wrap(self, no_wrap: bool) -> Self
Keeps the text on one line; see no_wrap.
pub fn with_weight(self, weight: u16) -> Self
Sourcepub fn with_shadow(self, shadow: Shadow) -> Self
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.
pub fn with_italic(self, italic: bool) -> Self
pub fn with_align(self, align: TextAlign) -> Self
pub fn with_max_lines(self, max_lines: u16) -> Self
pub fn with_ellipsis(self, ellipsis: bool) -> Self
pub fn with_line_height(self, line_height: f32) -> Self
pub fn with_letter_spacing(self, letter_spacing: f32) -> Self
Sourcepub fn with_raster(self, raster: GlyphRaster) -> Self
pub fn with_raster(self, raster: GlyphRaster) -> Self
Puts the glyphs on whole pixels with coverage resolved to on or off. See GlyphRaster.