Struct winit_modular::event_loop::EventLoop
source · [−]pub struct EventLoop { /* private fields */ }Expand description
A proxy event loop.
Similar API to winit::event_loop::EventLoop, except:
- You can create multiples of these and even run them at the same time, on separate threads
- You can create these on separate threads
- You can stop these loops without exiting your entire application
The “actual” single event loop must be created via [winit_modular::run]. This forwards all of its messages to the event loop using channels and returns the responses.
Implementations
sourceimpl EventLoop
impl EventLoop
sourcepub fn new() -> FutEventLoop
pub fn new() -> FutEventLoop
Creates a new proxy event loop. However it must first be registered, so this is async.
sourcepub fn on_main_thread<R: Any + Send>(
&self,
action: impl FnOnce() -> R + Send + 'static
) -> FutResponse<'_, R>
pub fn on_main_thread<R: Any + Send>(
&self,
action: impl FnOnce() -> R + Send + 'static
) -> FutResponse<'_, R>
Runs an arbitrary closure on the main / UI thread.
Note that the closure must be 'static, which means it can’t reference local variables.
To get around this, you can convert them to raw pointers, wrap them in an unsafe Send struct,
and unsafe dereference them inside the closure. This should actually be 100% safe as long
as you await and do not drop the Future, as those references will remain alive and won’t
be dereferenced outside of the closure until the future ends.
Alternatively, to get around this without unsafe, you can move the local variables into
the closure and then return them along with your “real” result.
In the future, we may provide more methods to work around this limitation.
sourcepub fn create_window(
&self,
configure: impl FnOnce(WindowBuilder) -> WindowBuilder + Send + 'static
) -> FutResponse<'_, Result<Window, OsError>>
pub fn create_window(
&self,
configure: impl FnOnce(WindowBuilder) -> WindowBuilder + Send + 'static
) -> FutResponse<'_, Result<Window, OsError>>
Creates a new Window, using the function to add arguments
sourcepub fn run(&self, event_handler: impl FnMut(Event, &mut ControlFlow, EventIs))
pub fn run(&self, event_handler: impl FnMut(Event, &mut ControlFlow, EventIs))
Receives new and buffered events and responses from the main loop, blocking waiting for new responses, until the event handler explicitly exits.
The third argument to event_handler is whether the event is buffered (i.e. sent before this was called) or new.
sourcepub async fn run_async(
&self,
event_handler: impl FnMut(Event, &mut ControlFlow, EventIs)
)
pub async fn run_async(
&self,
event_handler: impl FnMut(Event, &mut ControlFlow, EventIs)
)
Receives new and buffered events and responses from the main loop, blocking waiting for new responses, until the event handler explicitly exits.
The third argument to event_handler is whether the event is buffered (i.e. sent before this was called) or new.
sourcepub fn run_immediate(&self, event_handler: impl FnMut(Event, &mut ControlFlow))
pub fn run_immediate(&self, event_handler: impl FnMut(Event, &mut ControlFlow))
Receives all buffered events and responses from the main loop, not blocking for new events.
You can set ControlFlow to exit locally or exit the app, but ControlFlow::Wait and ControlFlow::WaitUntil won’t do anything.
Auto Trait Implementations
impl !RefUnwindSafe for EventLoop
impl !Send for EventLoop
impl !Sync for EventLoop
impl Unpin for EventLoop
impl !UnwindSafe for EventLoop
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more