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
use crate::{display::SimulatorDisplay, theme::BinaryColorTheme, window::Window};
use embedded_graphics::{geometry::Size, pixelcolor::PixelColor, DrawTarget};
#[derive(Debug)]
pub struct WindowBuilder {
display_size: Size,
scale: usize,
pixel_spacing: usize,
theme: BinaryColorTheme,
title: String,
}
impl WindowBuilder {
pub fn new<C>(display: &SimulatorDisplay<C>) -> Self
where
C: PixelColor,
{
Self {
display_size: display.size(),
scale: 1,
pixel_spacing: 0,
theme: BinaryColorTheme::Default,
title: String::from("embedded-graphics-simulator"),
}
}
pub fn scale(&mut self, scale: usize) -> &mut Self {
if scale == 0 {
panic!("scale must be >= 0");
}
self.scale = scale;
self
}
pub fn theme(&mut self, theme: BinaryColorTheme) -> &mut Self {
self.theme = theme;
self.scale(3);
self.pixel_spacing(1);
self
}
pub fn pixel_spacing(&mut self, pixel_spacing: usize) -> &mut Self {
self.pixel_spacing = pixel_spacing;
self
}
pub fn title(&mut self, title: &str) -> &mut Self {
self.title = title.to_owned();
self
}
pub fn build(&self) -> Window {
Window::new(
self.display_size,
self.scale,
self.pixel_spacing,
self.theme,
&self.title,
)
}
}