mod proxy; pub(crate) mod runner; mod state; mod window_target; pub use self::proxy::EventLoopProxy; pub use self::window_target::EventLoopWindowTarget; use super::{backend, device, window}; use crate::event::Event; use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget}; use std::marker::PhantomData; pub struct EventLoop { elw: RootEventLoopWindowTarget, } #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)] pub(crate) struct PlatformSpecificEventLoopAttributes {} impl EventLoop { pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Self { EventLoop { elw: RootEventLoopWindowTarget { p: EventLoopWindowTarget::new(), _marker: PhantomData, }, } } pub fn run(self, event_handler: F) -> ! where F: 'static + FnMut(Event, &RootEventLoopWindowTarget, &mut ControlFlow), { self.spawn_inner(event_handler, false); // Throw an exception to break out of Rust execution and use unreachable to tell the // compiler this function won't return, giving it a return type of '!' backend::throw( "Using exceptions for control flow, don't mind me. This isn't actually an error!", ); unreachable!(); } pub fn spawn(self, event_handler: F) where F: 'static + FnMut(Event, &RootEventLoopWindowTarget, &mut ControlFlow), { self.spawn_inner(event_handler, true); } fn spawn_inner(self, mut event_handler: F, event_loop_recreation: bool) where F: 'static + FnMut(Event, &RootEventLoopWindowTarget, &mut ControlFlow), { let target = RootEventLoopWindowTarget { p: self.elw.p.clone(), _marker: PhantomData, }; self.elw.p.run( Box::new(move |event, flow| event_handler(event, &target, flow)), event_loop_recreation, ); } pub fn create_proxy(&self) -> EventLoopProxy { self.elw.p.proxy() } pub fn window_target(&self) -> &RootEventLoopWindowTarget { &self.elw } }