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
use graphics::*;
use opengl_graphics::GlGraphics;
use crate::widget::config::*;
use crate::widget::widget::*;
pub struct BoxWidget {
config: Configurable,
}
impl BoxWidget {
pub fn new() -> Self {
Self {
config: Configurable::new(),
}
}
fn draw_box(&mut self, c: Context, g: &mut GlGraphics, clip: &DrawState) {
let size: crate::core::point::Size = self.config().get_size(CONFIG_BODY_SIZE);
let border: f64 = self.config().get_numeric(CONFIG_BORDER_WIDTH) as f64;
let color: types::Color = self.config().get_color(CONFIG_BORDER_COLOR);
let fill_color: types::Color = self.config().get_color(CONFIG_MAIN_COLOR);
g.rectangle(
&Rectangle::new(fill_color),
[0.0f64, 0.0f64, size.w as f64, size.h as f64],
clip,
c.transform.clone(),
);
Rectangle::new_border(color, border).draw(
[
0.0 as f64 + border as f64,
0.0 as f64 + border as f64,
size.w as f64 - (border as f64 * 2.0),
size.h as f64 - (border as f64 * 2.0),
],
clip,
c.transform.clone(),
g,
);
}
}
impl Widget for BoxWidget {
fn config(&mut self) -> &mut Configurable {
&mut self.config
}
fn set_config(&mut self, config: u8, config_value: Config) {
self.config().set(config, config_value.clone());
self.invalidate();
}
fn draw(&mut self, c: Context, g: &mut GlGraphics, clip: &DrawState) {
self.draw_box(c, g, &clip);
self.clear_invalidate();
}
}