use macroquad::{
    text::{TextDimensions, measure_text},
    window::screen_width,
};

#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub enum FontSize {
    Small,
    Medium,
    Large,
}

impl FontSize {
    pub fn size(&self) -> u16 {
        let size1 = measure_text("A", None, 10, 1.0);
        let size2 = measure_text("A", None, 20, 1.0);

        let scale_factor = size2.width - size1.width / 10.0;

        let offset = size2.width - (10.0 * scale_factor);

        let base_font_size = screen_width() * 0.01 - offset / scale_factor;

        (match self {
            FontSize::Small => base_font_size,
            FontSize::Medium => base_font_size * 1.0,
            FontSize::Large => base_font_size * 2.0,
        }) as u16
    }

    pub fn measure(&self, text: &str) -> TextDimensions {
        measure_text(text, None, self.size(), 1.0)
    }
}
