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
use super::*;
#[derive(Default)]
pub struct Label {
offset: Vec2,
size: Vec2,
scale: f32,
text: String,
}
impl Label {
pub fn draw<'s>(&'s mut self, r: &mut RenderLock<'s>, t: &'s Theme, pos: Vec2, size: Vec2, text: &str) {
if self.text != text || self.size != size {
let (offset, scale) = util::fit_text(text, t, size);
*self = Self {
offset,
size,
scale,
text: text.into(),
};
}
r.draw(Rect { pos, size, color: t.fg });
r.draw(Text {
pos: pos.sum(self.offset),
color: t.text,
scale: self.scale,
text,
font: &t.font,
});
}
}