use std::ops::{Deref, DerefMut};
lazy_static::lazy_static! {
pub(crate) static ref DEFAULT_FONT: Font = Font {
name: "Calibri".into(),
size: 8,
};
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Font {
pub(crate) name: Box<str>,
pub(crate) size: u16,
}
impl Font {
pub fn name(&self) -> &str {
&self.name
}
pub fn size(&self) -> u16 {
self.size
}
}
impl Default for &Font {
fn default() -> Self {
&DEFAULT_FONT
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct FontCollection(Vec<Font>);
impl FontCollection {
pub(crate) fn get_idx(&self, idx: usize) -> &Font {
&self.0[idx
.checked_sub(1)
.expect("guess Altium doesn't use one indexing")]
}
pub(crate) fn iter(&self) -> impl Iterator<Item = &Font> {
self.0.iter()
}
}
impl From<Vec<Font>> for FontCollection {
fn from(value: Vec<Font>) -> Self {
Self(value)
}
}
impl Deref for FontCollection {
type Target = [Font];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for FontCollection {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}