1use lambda_platform::winit::{
4 Loop,
5 WindowHandle,
6 WindowHandleBuilder,
7 WindowProperties,
8};
9
10use crate::events::Events;
11
12pub struct WindowBuilder {
15 name: String,
16 dimensions: (u32, u32),
17 vsync: bool,
18}
19
20impl WindowBuilder {
21 pub fn new() -> Self {
26 return Self {
27 name: String::from("Window"),
28 dimensions: (480, 360),
29 vsync: false,
30 };
31 }
32
33 pub fn with_name(mut self, name: &str) -> Self {
35 self.name = name.to_string();
36 return self;
37 }
38
39 pub fn with_dimensions(mut self, width: u32, height: u32) -> Self {
41 self.dimensions = (width, height);
42 return self;
43 }
44
45 pub fn with_vsync(mut self, vsync: bool) -> Self {
46 return self;
47 }
48
49 pub fn build(self, event_loop: &mut Loop<Events>) -> Window {
51 return Window::new(self.name.as_str(), self.dimensions, event_loop);
52 }
53}
54
55pub struct Window {
57 window_handle: WindowHandle,
58}
59
60impl Window {
61 fn new(
62 name: &str,
63 dimensions: (u32, u32),
64 event_loop: &mut Loop<Events>,
65 ) -> Self {
66 let monitor_handle = event_loop.get_primary_monitor().unwrap_or(
69 event_loop
70 .get_any_available_monitors()
71 .expect("No monitors available"),
72 );
73
74 let window_properties = WindowProperties {
75 name: name.to_string(),
76 dimensions,
77 monitor_handle,
78 };
79
80 let window_handle = WindowHandleBuilder::new()
81 .with_window_properties(window_properties, event_loop)
82 .build();
83
84 logging::debug!("Created window: {}", name);
85 return Self { window_handle };
86 }
87
88 pub fn redraw(&self) {
90 self.window_handle.window_handle.request_redraw();
91 }
92
93 pub fn window_handle(&self) -> &WindowHandle {
95 return &self.window_handle;
96 }
97
98 pub fn dimensions(&self) -> (u32, u32) {
100 return (
101 self.window_handle.size.width,
102 self.window_handle.size.height,
103 );
104 }
105}