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
use super::*;
pub struct Label {
font_ref: FontRef,
pos: (i32, i32),
text: String
}
impl Label {
pub fn new(font_ref: FontRef) -> Self {
Label {
font_ref,
pos: (0, 0),
text: String::new()
}
}
pub fn pos(&self) -> (i32, i32) {
self.pos
}
pub fn with_pos(mut self, x: i32, y: i32) -> Self {
self.pos = (x, y);
self
}
pub fn set_pos(&mut self, x: i32, y: i32) {
self.pos = (x, y);
}
pub fn text(&self) -> &String {
&self.text
}
pub fn with_text(mut self, text: &str) -> Self {
self.text = String::from(text);
self
}
pub fn set_text(&mut self, text: &str) {
self.text = String::from(text);
}
}
impl Control for Label {
fn update(&mut self, _args: &ControlState, _res: &Resources) { }
fn draw(&self, buffer: &mut Vec<u32>, buffer_width: usize, res: &Resources) {
let font = res.get_font(self.font_ref).unwrap();
font.draw_string(buffer, buffer_width, &self.text, self.pos);
}
fn control_type(&self) -> ControlType {
ControlType::Label
}
fn as_any(&self) -> &Any {
self
}
fn as_any_mut(&mut self) -> &mut Any {
self
}
}