Part of #3367, opening to discuss separately.
Winit needs some way for the user to synchronously respond to events with a value.
Prominent examples include:
To do this, we propose allowing the user to implement a trait, where each method is a callback that will be called when a certain event happens. Roughly:
// API
pub trait ApplicationHandler {
fn new_events(&mut self, event_loop: ActiveEventLoop<'_>, start_cause: StartCause);
fn resized(
&mut self,
event_loop: ActiveEventLoop<'_>,
window_id: WindowId,
size: PhysicalSize<u32>
) -> bool;
// ... Further events
}
// User code
struct App {
window: Option<Window>,
}
impl Application for App { ... }
fn main() {
event_loop.run(App { window: None })?;
}
Feel free to update this code-block once we narrow down the actual API.
Identified problems to which we need some sort of solution:
Implementation plan:
Part of #3367, opening to discuss separately.
Winit needs some way for the user to synchronously respond to events with a value.
Prominent examples include:
Backbutton/KeyCodeon Android #2304 (requires saying that you've handled, otherwise you'll block everything)To do this, we propose allowing the user to implement a trait, where each method is a callback that will be called when a certain event happens. Roughly:
Feel free to update this code-block once we narrow down the actual API.
Identified problems to which we need some sort of solution:
egui-winitson_window_event.dbg!(event)and similar logging that access all events.Implementation plan:
ApplicationHandler, while still keeping theEvent-based API around to ease transition. Initial work in Begin transition to a trait-based system #3386.ApplicationHandler#3387.