2019-06-25 03:15:34 +02:00
|
|
|
mod proxy;
|
|
|
|
|
mod runner;
|
|
|
|
|
mod state;
|
|
|
|
|
mod window_target;
|
|
|
|
|
|
2022-03-18 14:09:39 +01:00
|
|
|
pub use self::proxy::EventLoopProxy;
|
|
|
|
|
pub use self::window_target::EventLoopWindowTarget;
|
2019-06-25 03:15:34 +02:00
|
|
|
|
2020-08-17 16:48:29 -07:00
|
|
|
use super::{backend, device, window};
|
2019-06-25 21:01:13 +02:00
|
|
|
use crate::event::Event;
|
2022-03-18 14:09:39 +01:00
|
|
|
use crate::event_loop::{ControlFlow, EventLoopWindowTarget as RootEventLoopWindowTarget};
|
2019-06-25 03:15:34 +02:00
|
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
|
|
|
|
|
pub struct EventLoop<T: 'static> {
|
2022-03-18 14:09:39 +01:00
|
|
|
elw: RootEventLoopWindowTarget<T>,
|
2019-06-25 03:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 22:09:03 +01:00
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Hash)]
|
|
|
|
|
pub(crate) struct PlatformSpecificEventLoopAttributes {}
|
|
|
|
|
|
2019-06-25 03:15:34 +02:00
|
|
|
impl<T> EventLoop<T> {
|
2022-02-16 22:09:03 +01:00
|
|
|
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> Self {
|
2019-06-25 03:15:34 +02:00
|
|
|
EventLoop {
|
2022-03-18 14:09:39 +01:00
|
|
|
elw: RootEventLoopWindowTarget {
|
|
|
|
|
p: EventLoopWindowTarget::new(),
|
2019-06-25 03:15:34 +02:00
|
|
|
_marker: PhantomData,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn run<F>(self, mut event_handler: F) -> !
|
|
|
|
|
where
|
2022-03-18 14:09:39 +01:00
|
|
|
F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
2019-06-25 03:15:34 +02:00
|
|
|
{
|
2022-03-18 14:09:39 +01:00
|
|
|
let target = RootEventLoopWindowTarget {
|
2019-06-25 03:15:34 +02:00
|
|
|
p: self.elw.p.clone(),
|
|
|
|
|
_marker: PhantomData,
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-25 21:01:13 +02:00
|
|
|
self.elw.p.run(Box::new(move |event, flow| {
|
2019-06-25 03:15:34 +02:00
|
|
|
event_handler(event, &target, flow)
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Throw an exception to break out of Rust exceution 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!();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 14:09:39 +01:00
|
|
|
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
2019-06-25 03:15:34 +02:00
|
|
|
self.elw.p.proxy()
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-18 14:09:39 +01:00
|
|
|
pub fn window_target(&self) -> &RootEventLoopWindowTarget<T> {
|
2019-06-25 03:15:34 +02:00
|
|
|
&self.elw
|
|
|
|
|
}
|
|
|
|
|
}
|