use super::weight::FontWeight;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum TextFamily {
#[default]
Proportional,
Monospace,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MonospaceMetrics {
pub cell_width: f32,
pub line_height: f32,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct TextFont {
pub weight: FontWeight,
pub family: TextFamily,
pub tabular: bool,
}
impl TextFont {
pub fn new(weight: FontWeight, family: TextFamily, tabular: bool) -> Self {
Self {
weight,
family,
tabular: tabular && family == TextFamily::Proportional,
}
}
pub(crate) fn monospace(self) -> bool {
self.family == TextFamily::Monospace
}
pub(crate) fn is_plain(self) -> bool {
self.family == TextFamily::Proportional && !self.tabular
}
}
impl From<FontWeight> for TextFont {
fn from(weight: FontWeight) -> Self {
Self::new(weight, TextFamily::Proportional, false)
}
}