ailloli_ui_winit/application.rs
1//! Shared winit application loop entry for binaries and examples.
2
3use winit::application::ApplicationHandler;
4use winit::event_loop::ControlFlow;
5
6use crate::event_loop::{new_event_loop, run_app_on_event_loop};
7
8/// Creates a winit event loop, applies `control_flow`, and runs the handler.
9///
10/// The call blocks until the event loop exits. On Linux, the shared runner also
11/// installs Ctrl+C wake-up handling and normalizes winit's teardown status-one quirk.
12///
13/// # Errors
14///
15/// Propagates event-loop construction and non-normalized run errors.
16///
17/// # Examples
18///
19/// ```no_run
20/// use ailloli_ui_winit::run_app;
21/// use winit::{application::ApplicationHandler, event_loop::ControlFlow};
22/// fn run<A: ApplicationHandler + 'static>(app: A) {
23/// run_app(app, ControlFlow::Wait).unwrap();
24/// }
25/// ```
26pub fn run_app<A: ApplicationHandler + 'static>(
27 mut app: A,
28 control_flow: ControlFlow,
29) -> Result<(), winit::error::EventLoopError> {
30 let event_loop = new_event_loop()?;
31 run_app_on_event_loop(event_loop, &mut app, control_flow)
32}