pub struct Font {
pub family: &'static str,
pub size: f32,
pub weight: u16,
pub italic: bool,
pub letter_spacing: f32,
pub features: &'static [FontFeature],
}Expand description
A font: family, size, weight, slant, letter spacing and OpenType features.
The family is resolved through fontconfig, so generic names such as
"sans-serif" and "monospace" work too.
use crabshell_ui::{Font, FontFeature};
const CLOCK: Font = Font::new("sans-serif", 13.0).features(&[FontFeature::TABULAR_NUMBERS]);
const NOTE: Font = Font::new("sans-serif", 11.0).italic().letter_spacing(0.5);Fields§
§family: &'static strThe family name, such as "Inter" or "sans-serif".
size: f32The size in logical pixels.
weight: u16The weight, from 100 (thin) through 400 (regular) and 700 (bold) to 900 (black).
italic: boolWhether the italic face is asked for.
letter_spacing: f32Extra logical pixels after each glyph, at least minus half the size; a number that isn’t finite counts as 0.
features: &'static [FontFeature]OpenType features turned on or off, in order.
Implementations§
Source§impl Font
impl Font
Sourcepub const fn new(family: &'static str, size: f32) -> Font
pub const fn new(family: &'static str, size: f32) -> Font
A regular-weight font of family at size logical pixels.
Sourcepub const fn weight(self, weight: u16) -> Font
pub const fn weight(self, weight: u16) -> Font
The same font with another weight, such as 700 for bold.
Sourcepub const fn italic(self) -> Font
pub const fn italic(self) -> Font
The same font in italic. A family without an italic face gets the face fontconfig picks, slanted by the renderer if it is upright.
Sourcepub const fn letter_spacing(self, px: f32) -> Font
pub const fn letter_spacing(self, px: f32) -> Font
The same font with px extra logical pixels after each glyph, or
less with a negative number, down to minus half the font size.
Sourcepub const fn features(self, features: &'static [FontFeature]) -> Font
pub const fn features(self, features: &'static [FontFeature]) -> Font
The same font with these OpenType features, such as
FontFeature::TABULAR_NUMBERS for digits of one width.