mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Add platform::desktop module with EventLoopExt::run_return
This commit is contained in:
28
src/platform/desktop.rs
Normal file
28
src/platform/desktop.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#![cfg(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"
|
||||
))]
|
||||
|
||||
use {EventLoop, Event, ControlFlow};
|
||||
|
||||
/// Additional methods on `EventLoop` that are specific to desktop platforms.
|
||||
pub trait EventLoopExtDesktop {
|
||||
type UserEvent;
|
||||
/// Initializes the `winit` event loop.
|
||||
///
|
||||
/// Unlikes `run`, this function *does* return control flow to the caller when `control_flow`
|
||||
/// is set to `ControlFlow::Exit`.
|
||||
fn run_return<F>(&mut self, event_handler: F)
|
||||
where F: FnMut(Event<Self::UserEvent>, &EventLoop<Self::UserEvent>, &mut ControlFlow);
|
||||
}
|
||||
|
||||
impl<T> EventLoopExtDesktop for EventLoop<T> {
|
||||
type UserEvent = T;
|
||||
|
||||
fn run_return<F>(&mut self, event_handler: F)
|
||||
where F: FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)
|
||||
{
|
||||
self.events_loop.run_return(event_handler)
|
||||
}
|
||||
}
|
||||
@@ -15,3 +15,5 @@ pub mod ios;
|
||||
pub mod macos;
|
||||
pub mod unix;
|
||||
pub mod windows;
|
||||
|
||||
pub mod desktop;
|
||||
|
||||
Reference in New Issue
Block a user