#[derive(Debug, Clone, Copy)]
pub struct TextMetrics {
pub width: f32,
pub height: f32,
}
impl TextMetrics {
#[must_use]
pub const fn new(width: f32, height: f32) -> Self {
Self { width, height }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FontStyle {
#[default]
Normal,
Italic,
Oblique,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FontWeight {
Thin,
ExtraLight,
Light,
#[default]
Normal,
Medium,
SemiBold,
Bold,
ExtraBold,
Black,
}
impl FontWeight {
#[must_use]
pub const fn value(self) -> u16 {
match self {
Self::Thin => 100,
Self::ExtraLight => 200,
Self::Light => 300,
Self::Normal => 400,
Self::Medium => 500,
Self::SemiBold => 600,
Self::Bold => 700,
Self::ExtraBold => 800,
Self::Black => 900,
}
}
}
#[derive(Debug, Clone)]
pub struct FontSpec {
pub family: String,
pub size: f32,
pub weight: FontWeight,
pub style: FontStyle,
}
impl FontSpec {
#[must_use]
pub fn new(family: impl Into<String>, size: f32) -> Self {
Self {
family: family.into(),
size,
weight: FontWeight::default(),
style: FontStyle::default(),
}
}
#[must_use]
pub const fn with_weight(mut self, weight: FontWeight) -> Self {
self.weight = weight;
self
}
#[must_use]
pub const fn with_style(mut self, style: FontStyle) -> Self {
self.style = style;
self
}
}
impl Default for FontSpec {
fn default() -> Self {
Self {
family: "sans-serif".to_string(),
size: 16.0,
weight: FontWeight::default(),
style: FontStyle::default(),
}
}
}