summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-30 21:44:19 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-03-30 21:44:19 +0200
commit67db13ff7c727254182a8c4474bd962b205e2e99 (patch)
treef7dfba22c64ed4190521b2fde79c5dc5eecc4bed /src
parent00de9d0c9ba20b313ffb459ed291ea2b85e53d32 (diff)
downloadiced-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 'src')
-rw-r--r--src/application.rs11
-rw-r--r--src/settings.rs15
2 files changed, 22 insertions, 4 deletions
diff --git a/src/application.rs b/src/application.rs
index 83ce900a..7b7de6d4 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -184,6 +184,13 @@ pub trait Application: Sized {
1.0
}
+ /// Returns whether the [`Application`] should be terminated.
+ ///
+ /// By default, it returns `false`.
+ fn should_exit(&self) -> bool {
+ false
+ }
+
/// Runs the [`Application`].
///
/// On native platforms, this method will take control of the current thread
@@ -284,6 +291,10 @@ where
fn scale_factor(&self) -> f64 {
self.0.scale_factor()
}
+
+ fn should_exit(&self) -> bool {
+ self.0.should_exit()
+ }
}
#[cfg(target_arch = "wasm32")]
diff --git a/src/settings.rs b/src/settings.rs
index c82a1354..2b32258d 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -25,6 +25,10 @@ pub struct Settings<Flags> {
/// The default value is 20.
pub default_text_size: u16,
+ /// Whether the [`Application`] should exit when the user requests the
+ /// window to close (e.g. the user presses the close button).
+ pub exit_on_close_request: bool,
+
/// If set to true, the renderer will try to perform antialiasing for some
/// primitives.
///
@@ -46,10 +50,11 @@ impl<Flags> Settings<Flags> {
Self {
flags,
- antialiasing: default_settings.antialiasing,
+ window: default_settings.window,
default_font: default_settings.default_font,
default_text_size: default_settings.default_text_size,
- window: default_settings.window,
+ exit_on_close_request: default_settings.exit_on_close_request,
+ antialiasing: default_settings.antialiasing,
}
}
}
@@ -61,10 +66,11 @@ where
fn default() -> Self {
Self {
flags: Default::default(),
- antialiasing: Default::default(),
+ window: Default::default(),
default_font: Default::default(),
default_text_size: 20,
- window: Default::default(),
+ exit_on_close_request: true,
+ antialiasing: false,
}
}
}
@@ -75,6 +81,7 @@ impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> {
iced_winit::Settings {
window: settings.window.into(),
flags: settings.flags,
+ exit_on_close_request: settings.exit_on_close_request,
}
}
}