Add platform::desktop module with EventLoopExt::run_return

This commit is contained in:
Osspial
2018-08-22 22:07:39 -04:00
parent dad24d086a
commit f20fac99f6
4 changed files with 114 additions and 34 deletions

28
src/platform/desktop.rs Normal file
View 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)
}
}

View File

@@ -15,3 +15,5 @@ pub mod ios;
pub mod macos;
pub mod unix;
pub mod windows;
pub mod desktop;