add: ActiveEventLoop::create_proxy()
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
parent
2e93e48a3b
commit
a0d69c782a
14 changed files with 78 additions and 71 deletions
|
|
@ -3,6 +3,7 @@
|
|||
use std::cell::{RefCell, RefMut};
|
||||
use std::collections::HashSet;
|
||||
use std::os::raw::c_void;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
use std::time::Instant;
|
||||
use std::{fmt, mem, ptr};
|
||||
|
|
@ -135,6 +136,7 @@ pub(crate) struct AppState {
|
|||
app_state: Option<AppStateImpl>,
|
||||
control_flow: ControlFlow,
|
||||
waker: EventLoopWaker,
|
||||
proxy_wake_up: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
|
|
@ -158,6 +160,7 @@ impl AppState {
|
|||
}),
|
||||
control_flow: ControlFlow::default(),
|
||||
waker,
|
||||
proxy_wake_up: Arc::new(AtomicBool::new(false)),
|
||||
});
|
||||
}
|
||||
init_guard(&mut guard);
|
||||
|
|
@ -402,6 +405,10 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn proxy_wake_up(&self) -> Arc<AtomicBool> {
|
||||
self.proxy_wake_up.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn set_control_flow(&mut self, control_flow: ControlFlow) {
|
||||
self.control_flow = control_flow;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ pub struct ActiveEventLoop {
|
|||
}
|
||||
|
||||
impl ActiveEventLoop {
|
||||
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||
EventLoopProxy::new(AppState::get_mut(self.mtm).proxy_wake_up())
|
||||
}
|
||||
|
||||
pub fn create_custom_cursor(&self, source: CustomCursorSource) -> CustomCursor {
|
||||
let _ = source.inner;
|
||||
CustomCursor { inner: super::PlatformCustomCursor }
|
||||
|
|
@ -134,7 +138,6 @@ fn map_user_event<A: ApplicationHandler>(
|
|||
|
||||
pub struct EventLoop {
|
||||
mtm: MainThreadMarker,
|
||||
proxy_wake_up: Arc<AtomicBool>,
|
||||
window_target: RootActiveEventLoop,
|
||||
}
|
||||
|
||||
|
|
@ -160,11 +163,8 @@ impl EventLoop {
|
|||
// this line sets up the main run loop before `UIApplicationMain`
|
||||
setup_control_flow_observers();
|
||||
|
||||
let proxy_wake_up = Arc::new(AtomicBool::new(false));
|
||||
|
||||
Ok(EventLoop {
|
||||
mtm,
|
||||
proxy_wake_up,
|
||||
window_target: RootActiveEventLoop { p: ActiveEventLoop { mtm }, _marker: PhantomData },
|
||||
})
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ impl EventLoop {
|
|||
`EventLoop::run_app` calls `UIApplicationMain` on iOS",
|
||||
);
|
||||
|
||||
let handler = map_user_event(app, self.proxy_wake_up.clone());
|
||||
let handler = map_user_event(app, AppState::get_mut(self.mtm).proxy_wake_up());
|
||||
|
||||
let handler = unsafe {
|
||||
std::mem::transmute::<
|
||||
|
|
@ -212,10 +212,6 @@ impl EventLoop {
|
|||
unreachable!()
|
||||
}
|
||||
|
||||
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||
EventLoopProxy::new(self.proxy_wake_up.clone())
|
||||
}
|
||||
|
||||
pub fn window_target(&self) -> &RootActiveEventLoop {
|
||||
&self.window_target
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue