zenthra_platform/
window.rs1use std::sync::Arc;
2use zenthra_render::gpu::GpuContext;
3
4pub struct Window {
5 pub gpu: GpuContext,
6 pub winit_window: Arc<winit::window::Window>,
7 pub title: String,
8}
9
10impl Window {
11 pub async fn new(
12 event_loop: &winit::event_loop::ActiveEventLoop,
13 title: &str,
14 width: u32,
15 height: u32,
16 decorations: bool,
17 ) -> Self {
18 let attrs = winit::window::Window::default_attributes()
19 .with_title(title)
20 .with_inner_size(winit::dpi::LogicalSize::new(width, height))
21 .with_decorations(decorations);
22
23 let winit_window = Arc::new(event_loop.create_window(attrs).unwrap());
24 let gpu = GpuContext::new(winit_window.clone()).await;
25
26 Self {
27 gpu,
28 winit_window,
29 title: title.to_string(),
30 }
31 }
32
33 pub fn resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) {
34 let sf = self.winit_window.scale_factor();
35 self.gpu.resize(new_size, sf);
36 }
37
38 pub fn request_redraw(&self) {
39 self.winit_window.request_redraw();
40 }
41
42 pub fn scale_factor(&self) -> f64 {
43 self.gpu.scale_factor
44 }
45
46 pub fn width(&self) -> u32 {
47 self.gpu.size.width
48 }
49 pub fn height(&self) -> u32 {
50 self.gpu.size.height
51 }
52}