Skip to main content

aeth_window/
access_winit_window.rs

1/// Forward method from [`winit::window::Window`] to an
2/// extension of [`AccessWinitWindow`] trait.
3pub use aeth_window_macros::forward_winit_window_method;
4use winit::window::Window as WinitWindow;
5
6/// Trait to access to its internally owned
7/// [`winit::window::Window`] object.
8///
9/// This trait is made so that the user of this package
10/// can write
11/// `trait AccessWinitWindowExt : AccessWinitWindow`
12/// plus
13/// `impl<T> AccessWinitWindowExt for T where T: AccessWinitWindow {}`
14/// to extend the behaviour of our `Window` object.
15///
16/// Please notice not only the holder of Window but
17/// also the aeth-window subsystem will need to
18/// access the underlying [`winit::window::Window`]
19/// object. The holder is always an async task, and
20/// allowing it to hold a [`std::cell::Ref`] to the
21/// [`winit::window::Window`] can cause the window
22/// subsystem to fail when they also borrow an
23/// instance of it. So we enforce short-lived
24/// reference access here by forcing the operation
25/// on [`winit::window::Window`] to be completed
26/// within a function.
27pub trait AccessWinitWindow {
28    /// Manipulate the underlying [`winit::window::Window`]
29    /// in an immutable manner.
30    fn map_winit_window<F, T>(&self, f: F) -> T
31    where
32        F: FnOnce(&Box<dyn WinitWindow>) -> T;
33
34    /// Manipulate the underlying [`winit::window::Window`]
35    /// in a mutable manner.
36    fn map_winit_window_mut<F, T>(&mut self, f: F) -> T
37    where
38        F: FnOnce(&mut Box<dyn WinitWindow>) -> T;
39}
40
41/// Trait extension to forawrd
42/// [`winit::window::Window`] methods.
43///
44/// Please notice that we forward method based on the
45/// requirement of other modules from aeth-rs, and not
46/// necessarily all methods are forwarded. In that case,
47/// you may add your required method to this trait
48/// extension through pull request, or implement your
49/// own extension, just like what we are doing here.
50pub trait AccessWinitWindowExt: AccessWinitWindow {
51    #[forward_winit_window_method]
52    fn id(&self) -> winit::window::WindowId {
53        todo!()
54    }
55
56    #[forward_winit_window_method]
57    fn scale_factor(&self) -> f64 {
58        todo!()
59    }
60
61    #[forward_winit_window_method]
62    fn pre_present_notify(&self) {
63        todo!()
64    }
65
66    #[forward_winit_window_method]
67    fn surface_position(&self) -> winit::dpi::PhysicalPosition<i32> {
68        todo!()
69    }
70
71    #[forward_winit_window_method]
72    fn outer_position(
73        &self,
74    ) -> Result<winit::dpi::PhysicalPosition<i32>, winit::error::RequestError> {
75        todo!()
76    }
77
78    #[forward_winit_window_method]
79    fn set_outer_position(&self, position: winit::dpi::Position) {
80        todo!()
81    }
82
83    #[forward_winit_window_method]
84    fn surface_size(&self) -> winit::dpi::PhysicalSize<u32> {
85        todo!()
86    }
87
88    #[forward_winit_window_method]
89    fn request_surface_size(
90        &self,
91        size: winit::dpi::Size,
92    ) -> Option<winit::dpi::PhysicalSize<u32>> {
93        todo!()
94    }
95
96    #[forward_winit_window_method]
97    fn outer_size(&self) -> winit::dpi::PhysicalSize<u32> {
98        todo!()
99    }
100
101    #[forward_winit_window_method]
102    fn safe_area(&self) -> winit::dpi::PhysicalInsets<u32> {
103        todo!()
104    }
105
106    #[forward_winit_window_method]
107    fn set_min_surface_size(&self, min_size: Option<winit::dpi::Size>) {
108        todo!()
109    }
110
111    #[forward_winit_window_method]
112    fn set_max_surface_size(&self, min_size: Option<winit::dpi::Size>) {
113        todo!()
114    }
115
116    #[forward_winit_window_method]
117    fn surface_resize_increments(&self) -> Option<winit::dpi::PhysicalSize<u32>> {
118        todo!()
119    }
120
121    #[forward_winit_window_method]
122    fn set_surface_resize_increments(&self, increments: Option<winit::dpi::Size>) {
123        todo!()
124    }
125
126    #[forward_winit_window_method]
127    fn title(&self) -> String {
128        todo!()
129    }
130
131    #[forward_winit_window_method]
132    fn set_title(&self, title: &str) {
133        todo!()
134    }
135
136    #[forward_winit_window_method]
137    fn set_transparent(&self, transparent: bool) {
138        todo!()
139    }
140}
141
142impl<T> AccessWinitWindowExt for T where T: AccessWinitWindow {}