diff options
author | 2021-03-30 21:44:19 +0200 | |
---|---|---|
committer | 2021-03-30 21:44:19 +0200 | |
commit | 67db13ff7c727254182a8c4474bd962b205e2e99 (patch) | |
tree | f7dfba22c64ed4190521b2fde79c5dc5eecc4bed /glutin | |
parent | 00de9d0c9ba20b313ffb459ed291ea2b85e53d32 (diff) | |
download | iced-67db13ff7c727254182a8c4474bd962b205e2e99.tar.gz iced-67db13ff7c727254182a8c4474bd962b205e2e99.tar.bz2 iced-67db13ff7c727254182a8c4474bd962b205e2e99.zip |
Add support for graceful exits in `Application`
- `Settings` now contains an `exit_on_close_request` field
- `Application` has a new `should_exit` method
Diffstat (limited to 'glutin')
-rw-r--r-- | glutin/src/application.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 163bc9f9..79fcf745 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -92,10 +92,11 @@ where application, compositor, renderer, - context, runtime, debug, receiver, + context, + settings.exit_on_close_request, )); let mut context = task::Context::from_waker(task::noop_waker_ref()); @@ -139,10 +140,11 @@ async fn run_instance<A, E, C>( mut application: A, mut compositor: C, mut renderer: A::Renderer, - context: glutin::ContextWrapper<glutin::PossiblyCurrent, Window>, mut runtime: Runtime<E, Proxy<A::Message>, A::Message>, mut debug: Debug, mut receiver: mpsc::UnboundedReceiver<glutin::event::Event<'_, A::Message>>, + context: glutin::ContextWrapper<glutin::PossiblyCurrent, Window>, + exit_on_close_request: bool, ) where A: Application + 'static, E: Executor + 'static, @@ -212,6 +214,8 @@ async fn run_instance<A, E, C>( // Update window state.synchronize(&application, context.window()); + let should_exit = application.should_exit(); + user_interface = ManuallyDrop::new(application::build_user_interface( &mut application, @@ -220,6 +224,10 @@ async fn run_instance<A, E, C>( state.logical_size(), &mut debug, )); + + if should_exit { + break; + } } debug.draw_started(); @@ -290,6 +298,7 @@ async fn run_instance<A, E, C>( .. } => { if application::requests_exit(&window_event, state.modifiers()) + && exit_on_close_request { break; } |