pub trait EventLoopProvider: Debug {
// Required methods
fn run_app<A: ApplicationHandler + 'static>(
self,
app: A,
) -> Result<(), EventLoopError>;
fn create_proxy(&self) -> EventLoopProxy;
fn owned_display_handle(&self) -> OwnedDisplayHandle;
fn listen_device_events(&self, allowed: DeviceEvents);
fn set_control_flow(&self, control_flow: ControlFlow);
fn create_custom_cursor(
&self,
custom_cursor: CustomCursorSource,
) -> Result<CustomCursor, CustomCursorError>;
}Expand description
Common methods to implement for the platform event loop.
Required Methods§
Sourcefn run_app<A: ApplicationHandler + 'static>(
self,
app: A,
) -> Result<(), EventLoopError>
fn run_app<A: ApplicationHandler + 'static>( self, app: A, ) -> Result<(), EventLoopError>
Run the event loop with the given application on the calling thread.
The app is dropped when the event loop is shut down.
§Event loop flow
This function internally handles the different parts of a traditional event-handling loop. You can imagine this method as being implemented like this:
let mut start_cause = StartCause::Init;
// Run the event loop.
while !event_loop.exiting() {
// Wake up.
app.new_events(event_loop, start_cause);
// Indicate that surfaces can now safely be created.
if start_cause == StartCause::Init {
app.can_create_surfaces(event_loop);
}
// Handle proxy wake-up event.
if event_loop.proxy_wake_up_set() {
event_loop.proxy_wake_up_clear();
app.proxy_wake_up(event_loop);
}
// Handle actions done by the user / system such as moving the cursor, resizing the
// window, changing the window theme, etc.
for event in event_loop.events() {
match event {
window event => app.window_event(event_loop, window_id, event),
device event => app.device_event(event_loop, device_id, event),
}
}
// Handle redraws.
for window_id in event_loop.pending_redraws() {
app.window_event(event_loop, window_id, WindowEvent::RedrawRequested);
}
// Done handling events, wait until we're woken up again.
app.about_to_wait(event_loop);
start_cause = event_loop.wait_if_necessary();
}
// Finished running, drop application state.
drop(app);This is of course a very coarse-grained overview, and leaves out timing details like
ControlFlow::WaitUntil and life-cycle methods like ApplicationHandler::resumed, but
it should give you an idea of how things fit together.
§Returns
The semantics of this function is defined by the target platform. Consult the implementor docs for details.
Sourcefn create_proxy(&self) -> EventLoopProxy
fn create_proxy(&self) -> EventLoopProxy
Creates an EventLoopProxy that can be used to dispatch user events
to the main event loop, possibly from another thread.
Sourcefn owned_display_handle(&self) -> OwnedDisplayHandle
fn owned_display_handle(&self) -> OwnedDisplayHandle
Gets a persistent reference to the underlying platform display.
See the OwnedDisplayHandle type for more information.
Sourcefn listen_device_events(&self, allowed: DeviceEvents)
fn listen_device_events(&self, allowed: DeviceEvents)
Change if or when DeviceEvents are captured.
See ActiveEventLoop::listen_device_events for details.
Sourcefn set_control_flow(&self, control_flow: ControlFlow)
fn set_control_flow(&self, control_flow: ControlFlow)
Sets the ControlFlow.
Sourcefn create_custom_cursor(
&self,
custom_cursor: CustomCursorSource,
) -> Result<CustomCursor, CustomCursorError>
fn create_custom_cursor( &self, custom_cursor: CustomCursorSource, ) -> Result<CustomCursor, CustomCursorError>
Create custom cursor.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".