From 41e359a511b215e72015f804336c20835430266a Mon Sep 17 00:00:00 2001 From: sumibi-yakitori Date: Mon, 27 Jan 2020 04:36:57 +0900 Subject: [PATCH] Added a prototype for the application exit event handler. --- src/application.rs | 10 +++++++++- src/sandbox.rs | 6 ++++++ winit/src/application.rs | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/application.rs b/src/application.rs index 3a526f1b11..69b54d52b3 100644 --- a/src/application.rs +++ b/src/application.rs @@ -161,6 +161,9 @@ pub trait Application: Sized { window::Mode::Windowed } + /// APPLICATION EXIT EVENT + fn on_exit(&mut self); + /// Runs the [`Application`]. /// /// This method will take control of the current thread and __will NOT @@ -221,10 +224,12 @@ where fn subscription(&self) -> Subscription { self.0.subscription() } - fn view(&mut self) -> Element<'_, Self::Message> { self.0.view() } + fn on_exit(&mut self) { + self.0.on_exit() + } } #[cfg(target_arch = "wasm32")] @@ -251,4 +256,7 @@ where fn view(&mut self) -> Element<'_, Self::Message> { self.0.view() } + fn on_exit(&mut self) { + self.0.on_exit() + } } diff --git a/src/sandbox.rs b/src/sandbox.rs index 2c0332ff85..47156174fc 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -127,6 +127,9 @@ pub trait Sandbox { { ::run(settings) } + + /// APPLICATION EXIT EVENT + fn on_exit(&mut self); } impl Application for T @@ -157,4 +160,7 @@ where fn view(&mut self) -> Element<'_, T::Message> { T::view(self) } + fn on_exit(&mut self) { + T::on_exit(self) + } } diff --git a/winit/src/application.rs b/winit/src/application.rs index 4b21a93096..93163c87fe 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -89,6 +89,9 @@ pub trait Application: Sized { Mode::Windowed } + /// APPLICATION EXIT EVENT + fn on_exit(&mut self); + /// Runs the [`Application`]. /// /// This method will take control of the current thread and __will NOT @@ -296,6 +299,8 @@ pub trait Application: Sized { window.request_redraw(); } + // event::Event::LoopDestroyed => { + // } event::Event::UserEvent(message) => { external_messages.push(message); } @@ -346,6 +351,7 @@ pub trait Application: Sized { resized = true; } WindowEvent::CloseRequested => { + application.on_exit(); *control_flow = ControlFlow::Exit; } WindowEvent::CursorMoved { position, .. } => {