-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
B - bugDang, that shouldn't have happenedDang, that shouldn't have happenedC - needs discussionDirection must be ironed outDirection must be ironed outI - BREAKING CHANGES - apiDesign and usabilityDesign and usability
Description
We have a lot of invariants in how our events are delivered, but these are only vaguely documented. Examples of things that commonly go wrong:
- Initializing windows outside
NewEvents(Init)/Resumed - Not suspending / resetting the draw buffers on
Suspended
To remedy this situation, I propose we change the run method(s) to use a trait object instead of just a closure.
Initial draft for what typical usage will look like (this will need a lot of tweaking, especially with regards to ControlFlow, and possibly we should consider a SimpleApplication trait that handles some of this for you):
struct MyApp {
window: Window,
}
struct SuspendedApp {
// ...
}
impl ApplicationHandler for MyApp {
type SuspendedState = SuspendedApp;
fn init(event_loop: &EventLoopWindowTarget) -> Self {
let window = WindowBuilder::new().build(event_loop);
Self { window }
}
fn suspend(self) -> Self::SuspendedState {
todo!()
}
fn resume(state: Self::SuspendedState, event_loop: &EventLoopWindowTarget) -> Self {
todo!()
}
fn on_event(
&mut self,
event: Event<'_>,
event_loop: &EvenLoopWindowTarget,
control_flow: &mut ControlFlow,
) {
// The usual event handling in here
}
}
impl Drop for MyApp { ... } // LoopDestroyed
fn main() {
let event_loop = EventLoop::new();
event_loop.run::<MyApp>();
}The closure we have now is really nice though, we loose the easiness offered by that, but this is strictly more correct, which I think is important!
Again, this will need a lot of tweaking, opening as an issue first to gather opinions.
daxpedda, DasLixou, da-shalev, mickvangelderen and CptPotatomickvangelderen
Metadata
Metadata
Assignees
Labels
B - bugDang, that shouldn't have happenedDang, that shouldn't have happenedC - needs discussionDirection must be ironed outDirection must be ironed outI - BREAKING CHANGES - apiDesign and usabilityDesign and usability