Skip to main content

aeth_window/
access_winit_active_event_loop.rs

1/// Forward method from [`winit::event_loop::ActiveEventLoop`] to an
2/// extension of [`AccessWinitActiveEventLoop`] trait.
3pub use aeth_window_macros::forward_winit_active_event_loop_method;
4use winit::event_loop::ActiveEventLoop;
5
6/// Trait to access [`winit::event_loop::ActiveEventLoop`].
7///
8/// In fact, the active event loop is not available all
9/// the time, so accessing the active event loop will
10/// require the window subsystem to put them in correct
11/// timing. Thus the accessor must be asynchronous.
12#[allow(async_fn_in_trait)]
13pub trait AccessWinitActiveEventLoop {
14    /// Run the function in the place where the active event
15    /// loop is available.
16    async fn run_with_active_event_loop<F, T>(&self, f: F) -> T
17    where
18        F: FnOnce(&dyn ActiveEventLoop) -> T + 'static,
19        T: 'static;
20}
21
22/// Trait extension to forawrd
23/// [`winit::event_loop::ActiveEventLoop`] methods.
24///
25/// Please notice
26/// [`winit::event_loop::ActiveEventLoop::create_window`]
27/// will never be forwarded. You must always not
28/// do that, instead you must call
29/// [`crate::Manager::create_window`]
30/// to get things right.
31///
32/// The
33/// [`winit::event_loop::ActiveEventLoop::exit`]
34/// is not forwarded either. We treat the exiting
35/// of the main coroutine as exiting the event loop.
36#[allow(async_fn_in_trait)]
37pub trait AccessWinitActiveEventLoopExt: AccessWinitActiveEventLoop {
38    #[forward_winit_active_event_loop_method]
39    async fn create_proxy(&self) -> winit::event_loop::EventLoopProxy {
40        todo!()
41    }
42
43    #[forward_winit_active_event_loop_method]
44    async fn create_custom_cursor(
45        &self,
46        custom_cursor: winit::cursor::CustomCursorSource,
47    ) -> Result<winit::cursor::CustomCursor, winit::error::RequestError> {
48        todo!()
49    }
50
51    #[forward_winit_active_event_loop_method]
52    async fn available_monitors(&self) -> Box<dyn Iterator<Item = winit::monitor::MonitorHandle>> {
53        todo!()
54    }
55
56    #[forward_winit_active_event_loop_method]
57    async fn primary_monitor(&self) -> Option<winit::monitor::MonitorHandle> {
58        todo!()
59    }
60
61    #[forward_winit_active_event_loop_method]
62    async fn listen_device_events(&self, allowed: winit::event_loop::DeviceEvents) {
63        todo!()
64    }
65
66    #[forward_winit_active_event_loop_method]
67    async fn system_theme(&self) -> Option<winit::window::Theme> {
68        todo!()
69    }
70
71    #[forward_winit_active_event_loop_method]
72    async fn set_control_flow(&self, flow: winit::event_loop::ControlFlow) {
73        todo!()
74    }
75
76    #[forward_winit_active_event_loop_method]
77    async fn control_flow(&self) -> winit::event_loop::ControlFlow {
78        todo!()
79    }
80
81    #[forward_winit_active_event_loop_method]
82    async fn owned_display_handle(&self) -> winit::event_loop::OwnedDisplayHandle {
83        todo!()
84    }
85}
86
87impl<T> AccessWinitActiveEventLoopExt for T where T: AccessWinitActiveEventLoop {}