Expose a pointer of EventLoopProxy to process custom messages (#674)

This commit is contained in:
Junfeng Liu 2020-10-16 04:31:34 +08:00 committed by GitHub
parent b03d8da9bb
commit f66a72563e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,9 @@ use winit::{
#[derive(Default)]
pub struct WinitPlugin;
#[derive(Debug)]
pub struct EventLoopProxyPtr(pub usize);
impl Plugin for WinitPlugin {
fn build(&self, app: &mut AppBuilder) {
app
@ -134,6 +137,11 @@ pub fn winit_runner(mut app: App) {
let mut create_window_event_reader = EventReader::<CreateWindow>::default();
let mut app_exit_event_reader = EventReader::<AppExit>::default();
app.resources
.insert_thread_local(EventLoopProxyPtr(
Box::into_raw(Box::new(event_loop.create_proxy())) as usize,
));
handle_create_window_events(
&mut app.resources,
&event_loop,