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
use lambda_platform::winit::{
Loop,
WindowHandle,
WindowHandleBuilder,
WindowProperties,
};
use crate::events::Events;
pub struct WindowBuilder {
name: String,
dimensions: (u32, u32),
vsync: bool,
}
impl WindowBuilder {
pub fn new() -> Self {
return Self {
name: String::from("Window"),
dimensions: (480, 360),
vsync: false,
};
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = name.to_string();
return self;
}
pub fn with_dimensions(mut self, width: u32, height: u32) -> Self {
self.dimensions = (width, height);
return self;
}
pub fn with_vsync(mut self, vsync: bool) -> Self {
return self;
}
pub fn build(self, event_loop: &mut Loop<Events>) -> Window {
return Window::new(self.name.as_str(), self.dimensions, event_loop);
}
}
pub struct Window {
window_handle: WindowHandle,
}
impl Window {
fn new(
name: &str,
dimensions: (u32, u32),
event_loop: &mut Loop<Events>,
) -> Self {
let monitor_handle = event_loop.get_primary_monitor().unwrap_or(
event_loop
.get_any_available_monitors()
.expect("No monitors available"),
);
let window_properties = WindowProperties {
name: name.to_string(),
dimensions,
monitor_handle,
};
let window_handle = WindowHandleBuilder::new()
.with_window_properties(window_properties, event_loop)
.build();
return Self { window_handle };
}
pub fn redraw(&self) {
self.window_handle.window_handle.request_redraw();
}
pub fn window_handle(&self) -> &WindowHandle {
return &self.window_handle;
}
pub fn dimensions(&self) -> (u32, u32) {
return (
self.window_handle.size.width,
self.window_handle.size.height,
);
}
}