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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use crate::color::Color;
use crate::text::wrapping::WrappingStrategy;
use crate::text::TextSize;

/// Characters be drawn be at idx * char_width, idx * char_height
#[derive(Debug, Clone)]
pub struct TextFormat {
    color: Color,
    size: TextSize,
    wrap_at: WrappingStrategy,
    char_height: isize,
    char_width: isize,
}

impl TextFormat {
    pub fn new(wrap_at: WrappingStrategy, size: TextSize, color: Color) -> Self {
        Self {
            wrap_at,
            size,
            color,
            char_height: (size.get_size().1 + size.get_spacing()) as isize,
            char_width: (size.get_size().0 + size.get_spacing()) as isize,
        }
    }

    pub fn new_with_spacing(
        wrap_at: WrappingStrategy,
        size: TextSize,
        color: Color,
        char_height: isize,
        char_width: isize,
    ) -> Self {
        Self {
            wrap_at,
            size,
            color,
            char_height,
            char_width,
        }
    }
}

impl Default for TextFormat {
    fn default() -> Self {
        let size = TextSize::default();
        Self {
            wrap_at: WrappingStrategy::default(),
            size,
            color: Color::default(),
            char_height: (size.get_size().1 + size.get_spacing()) as isize,
            char_width: (size.get_size().0 + size.get_spacing()) as isize,
        }
    }
}

impl TextFormat {
    #[inline]
    pub fn wrapping(&self) -> WrappingStrategy {
        self.wrap_at
    }

    #[inline]
    pub fn size(&self) -> TextSize {
        self.size
    }

    #[inline]
    pub fn color(&self) -> Color {
        self.color
    }

    #[inline]
    pub fn line_spacing(&self) -> isize {
        self.char_height
    }

    #[inline]
    pub fn letter_spacing(&self) -> isize {
        self.char_width
    }

    #[inline]
    pub fn with_color(&self, color: Color) -> Self {
        TextFormat { color, ..*self }
    }
}

impl From<(Color, TextSize, WrappingStrategy, isize, isize)> for TextFormat {
    fn from(
        (color, size, wrap_at, char_height, char_width): (
            Color,
            TextSize,
            WrappingStrategy,
            isize,
            isize,
        ),
    ) -> Self {
        TextFormat {
            color,
            size,
            wrap_at,
            char_height,
            char_width,
        }
    }
}

impl From<(Color, TextSize, WrappingStrategy, isize)> for TextFormat {
    fn from(
        (color, size, wrap_at, char_height): (Color, TextSize, WrappingStrategy, isize),
    ) -> Self {
        TextFormat {
            color,
            size,
            wrap_at,
            char_height,
            ..Self::default()
        }
    }
}

impl From<(Color, TextSize, WrappingStrategy)> for TextFormat {
    fn from((color, size, wrap_at): (Color, TextSize, WrappingStrategy)) -> Self {
        TextFormat {
            color,
            size,
            wrap_at,
            ..Self::default()
        }
    }
}

impl From<(Color, TextSize)> for TextFormat {
    fn from((color, size): (Color, TextSize)) -> Self {
        TextFormat {
            color,
            size,
            ..Self::default()
        }
    }
}

impl From<Color> for TextFormat {
    fn from(color: Color) -> Self {
        TextFormat {
            color,
            ..Self::default()
        }
    }
}