1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use druid_shell::piet::{
    Color, FontFamily, PietText, PietTextLayout, Text, TextLayoutBuilder, TextStorage,
};

///
#[derive(Clone)]
pub struct Font {
    pub color: Color,
    pub font_family: FontFamily,
    pub font_size: f64,
}

impl Default for Font {
    fn default() -> Self {
        Font {
            color: Color::rgb8(255, 255, 255),
            font_family: FontFamily::SYSTEM_UI,
            font_size: 14.0,
        }
    }
}

impl Font {
    ///
    pub fn text_layout(&self, text: impl TextStorage) -> PietTextLayout {
        let mut piet_text = PietText::new_with_unique_state();

        piet_text
            .new_text_layout(text)
            .font(self.font_family.clone(), self.font_size)
            .text_color(self.color.clone())
            .build()
            .unwrap()
    }
}