From b5ab50b2a8a869d8d433d9e13878c1cf1d721414 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Dec 2022 03:06:04 +0100 Subject: Implement `window::close` action and remove `should_exit` --- winit/src/application.rs | 18 +++++++++--------- winit/src/window.rs | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index d17db2cd..0f9b562e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -93,13 +93,6 @@ where fn scale_factor(&self) -> f64 { 1.0 } - - /// Returns whether the [`Application`] should be terminated. - /// - /// By default, it returns `false`. - fn should_exit(&self) -> bool { - false - } } /// Runs an [`Application`] with an executor, compositor, and the provided @@ -255,6 +248,7 @@ async fn run_instance( let mut clipboard = Clipboard::connect(&window); let mut cache = user_interface::Cache::default(); let mut surface = compositor.create_surface(&window); + let mut should_exit = false; let mut state = State::new(&application, &window); let mut viewport_version = state.viewport_version(); @@ -275,6 +269,7 @@ async fn run_instance( init_command, &mut runtime, &mut clipboard, + &mut should_exit, &mut proxy, &mut debug, &window, @@ -336,6 +331,7 @@ async fn run_instance( &mut renderer, &mut runtime, &mut clipboard, + &mut should_exit, &mut proxy, &mut debug, &mut messages, @@ -346,8 +342,6 @@ async fn run_instance( // Update window state.synchronize(&application, &window); - let should_exit = application.should_exit(); - user_interface = ManuallyDrop::new(build_user_interface( &application, cache, @@ -555,6 +549,7 @@ pub fn update( renderer: &mut A::Renderer, runtime: &mut Runtime, A::Message>, clipboard: &mut Clipboard, + should_exit: &mut bool, proxy: &mut winit::event_loop::EventLoopProxy, debug: &mut Debug, messages: &mut Vec, @@ -578,6 +573,7 @@ pub fn update( command, runtime, clipboard, + should_exit, proxy, debug, window, @@ -598,6 +594,7 @@ pub fn run_command( command: Command, runtime: &mut Runtime, A::Message>, clipboard: &mut Clipboard, + should_exit: &mut bool, proxy: &mut winit::event_loop::EventLoopProxy, debug: &mut Debug, window: &winit::window::Window, @@ -629,6 +626,9 @@ pub fn run_command( } }, command::Action::Window(action) => match action { + window::Action::Close => { + *should_exit = true; + } window::Action::Drag => { let _res = window.drag_window(); } diff --git a/winit/src/window.rs b/winit/src/window.rs index 1e704c5b..f6b43a0f 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -4,6 +4,11 @@ use iced_native::window; pub use window::{Event, Mode}; +/// Closes the current window and exits the application. +pub fn close() -> Command { + Command::single(command::Action::Window(window::Action::Close)) +} + /// Begins dragging the window while the left mouse button is held. pub fn drag() -> Command { Command::single(command::Action::Window(window::Action::Drag)) -- cgit