1 mod proxy; 2 mod runner; 3 mod state; 4 mod window_target; 5 6 pub use self::proxy::Proxy; 7 pub use self::window_target::WindowTarget; 8 9 use super::{backend, device, window}; 10 use crate::event::Event; 11 use crate::event_loop as root; 12 13 use std::marker::PhantomData; 14 15 pub struct EventLoop<T: 'static> { 16 elw: root::EventLoopWindowTarget<T>, 17 } 18 19 impl<T> EventLoop<T> { new() -> Self20 pub fn new() -> Self { 21 EventLoop { 22 elw: root::EventLoopWindowTarget { 23 p: WindowTarget::new(), 24 _marker: PhantomData, 25 }, 26 } 27 } 28 run<F>(self, mut event_handler: F) -> ! where F: 'static + FnMut(Event<'static, T>, &root::EventLoopWindowTarget<T>, &mut root::ControlFlow),29 pub fn run<F>(self, mut event_handler: F) -> ! 30 where 31 F: 'static 32 + FnMut(Event<'static, T>, &root::EventLoopWindowTarget<T>, &mut root::ControlFlow), 33 { 34 let target = root::EventLoopWindowTarget { 35 p: self.elw.p.clone(), 36 _marker: PhantomData, 37 }; 38 39 self.elw.p.run(Box::new(move |event, flow| { 40 event_handler(event, &target, flow) 41 })); 42 43 // Throw an exception to break out of Rust exceution and use unreachable to tell the 44 // compiler this function won't return, giving it a return type of '!' 45 backend::throw( 46 "Using exceptions for control flow, don't mind me. This isn't actually an error!", 47 ); 48 49 unreachable!(); 50 } 51 create_proxy(&self) -> Proxy<T>52 pub fn create_proxy(&self) -> Proxy<T> { 53 self.elw.p.proxy() 54 } 55 window_target(&self) -> &root::EventLoopWindowTarget<T>56 pub fn window_target(&self) -> &root::EventLoopWindowTarget<T> { 57 &self.elw 58 } 59 } 60