Skip to content

Commit

Permalink
Added a prototype for the application exit event handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
sumibi-yakitori committed Jan 26, 2020
1 parent 0bdf1f2 commit 41e359a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -221,10 +224,12 @@ where
fn subscription(&self) -> Subscription<Self::Message> {
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")]
Expand All @@ -251,4 +256,7 @@ where
fn view(&mut self) -> Element<'_, Self::Message> {
self.0.view()
}
fn on_exit(&mut self) {
self.0.on_exit()
}
}
6 changes: 6 additions & 0 deletions src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ pub trait Sandbox {
{
<Self as Application>::run(settings)
}

/// APPLICATION EXIT EVENT
fn on_exit(&mut self);
}

impl<T> Application for T
Expand Down Expand Up @@ -157,4 +160,7 @@ where
fn view(&mut self) -> Element<'_, T::Message> {
T::view(self)
}
fn on_exit(&mut self) {
T::on_exit(self)
}
}
6 changes: 6 additions & 0 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -296,6 +299,8 @@ pub trait Application: Sized {

window.request_redraw();
}
// event::Event::LoopDestroyed => {
// }
event::Event::UserEvent(message) => {
external_messages.push(message);
}
Expand Down Expand Up @@ -346,6 +351,7 @@ pub trait Application: Sized {
resized = true;
}
WindowEvent::CloseRequested => {
application.on_exit();
*control_flow = ControlFlow::Exit;
}
WindowEvent::CursorMoved { position, .. } => {
Expand Down

0 comments on commit 41e359a

Please sign in to comment.