use std::fmt::Display;

#[derive(Default, Debug, Clone, Copy)]
pub struct Length(f32, Unit);

impl Length {
    pub fn is_zero(&self) -> bool {
        self.0 == 0.
    }
}

impl Display for Length {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}{}", self.0, self.1)
    }
}

pub type Coordinate = Length;

#[derive(Default, Debug, Clone, Copy)]
pub enum Unit {
    #[default]
    None,
    Em,
    Ex,
    Px,
    In,
    Cm,
    Mm,
    Pt,
    Pc,
}

impl Display for Unit {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Unit::None => f.write_str(""),
            Unit::Em => f.write_str("em"),
            Unit::Ex => f.write_str("ex"),
            Unit::Px => f.write_str("px"),
            Unit::In => f.write_str("in"),
            Unit::Cm => f.write_str("cm"),
            Unit::Mm => f.write_str("mm"),
            Unit::Pt => f.write_str("pt"),
            Unit::Pc => f.write_str("pc"),
        }
    }
}
