Introduce close_requested for multi-window
This commit is contained in:
parent
35331d0a41
commit
dc86bd0373
4 changed files with 26 additions and 4 deletions
|
|
@ -250,6 +250,10 @@ impl Application for Example {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn close_requested(&self, window: window::Id) -> Self::Message {
|
||||
Message::Window(window, WindowMessage::CloseWindow)
|
||||
}
|
||||
|
||||
fn view(&self, window_id: window::Id) -> Element<Message> {
|
||||
if let Some(window) = self.windows.get(&window_id) {
|
||||
let focus = window.focus;
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ pub trait Application: Sized {
|
|||
false
|
||||
}
|
||||
|
||||
/// TODO(derezzedex)
|
||||
fn close_requested(&self, window: window::Id) -> Self::Message;
|
||||
|
||||
/// Runs the [`Application`].
|
||||
///
|
||||
/// On native platforms, this method will take control of the current thread
|
||||
|
|
@ -207,4 +210,8 @@ where
|
|||
fn should_exit(&self) -> bool {
|
||||
self.0.should_exit()
|
||||
}
|
||||
|
||||
fn close_requested(&self, window: window::Id) -> Self::Message {
|
||||
self.0.close_requested(window)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,6 +147,9 @@ where
|
|||
fn should_exit(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// TODO(derezzedex)
|
||||
fn close_requested(&self, window: window::Id) -> Self::Message;
|
||||
}
|
||||
|
||||
/// Runs an [`Application`] with an executor, compositor, and the provided
|
||||
|
|
@ -296,7 +299,7 @@ async fn run_instance<A, E, C>(
|
|||
>,
|
||||
init_command: Command<A::Message>,
|
||||
mut windows: HashMap<window::Id, winit::window::Window>,
|
||||
exit_on_close_request: bool,
|
||||
_exit_on_close_request: bool,
|
||||
) where
|
||||
A: Application + 'static,
|
||||
E: Executor + 'static,
|
||||
|
|
@ -684,9 +687,13 @@ async fn run_instance<A, E, C>(
|
|||
if requests_exit(
|
||||
&window_event,
|
||||
window_state.state.modifiers(),
|
||||
) && exit_on_close_request
|
||||
) {
|
||||
if let Some(id) =
|
||||
window_ids.get(&window_id).cloned()
|
||||
{
|
||||
break;
|
||||
let message = application.close_requested(id);
|
||||
messages.push(message);
|
||||
}
|
||||
}
|
||||
|
||||
window_state.state.update(
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ pub struct Settings<Flags> {
|
|||
/// Whether the [`Application`] should exit when the user requests the
|
||||
/// window to close (e.g. the user presses the close button).
|
||||
///
|
||||
/// NOTE: This is not used for `multi-window`, instead check [`Application::close_requested`].
|
||||
///
|
||||
/// [`close_requested`]: crate::multi_window::Application::close_requested
|
||||
///
|
||||
/// [`Application`]: crate::Application
|
||||
pub exit_on_close_request: bool,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue