From 287306e1ebec610c31e37782320fe00d20a6c9ac Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 1 Apr 2022 17:27:19 -0300 Subject: Introduce `multi_window` in `iced_winit` --- winit/src/multi_window/state.rs | 212 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 winit/src/multi_window/state.rs (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs new file mode 100644 index 00000000..2d120ca1 --- /dev/null +++ b/winit/src/multi_window/state.rs @@ -0,0 +1,212 @@ +use crate::application::{self, StyleSheet as _}; +use crate::conversion; +use crate::multi_window::Application; +use crate::{Color, Debug, Point, Size, Viewport}; + +use std::marker::PhantomData; +use winit::event::{Touch, WindowEvent}; +use winit::window::Window; + +/// The state of a windowed [`Application`]. +#[allow(missing_debug_implementations)] +pub struct State +where + ::Theme: application::StyleSheet, +{ + title: String, + scale_factor: f64, + viewport: Viewport, + viewport_version: usize, + cursor_position: winit::dpi::PhysicalPosition, + modifiers: winit::event::ModifiersState, + theme: ::Theme, + appearance: application::Appearance, + application: PhantomData, +} + +impl State +where + ::Theme: application::StyleSheet, +{ + /// Creates a new [`State`] for the provided [`Application`] and window. + pub fn new(application: &A, window: &Window) -> Self { + let title = application.title(); + let scale_factor = application.scale_factor(); + let theme = application.theme(); + let appearance = theme.appearance(application.style()); + + let viewport = { + let physical_size = window.inner_size(); + + Viewport::with_physical_size( + Size::new(physical_size.width, physical_size.height), + window.scale_factor() * scale_factor, + ) + }; + + Self { + title, + scale_factor, + viewport, + viewport_version: 0, + // TODO: Encode cursor availability in the type-system + cursor_position: winit::dpi::PhysicalPosition::new(-1.0, -1.0), + modifiers: winit::event::ModifiersState::default(), + theme, + appearance, + application: PhantomData, + } + } + + /// Returns the current [`Viewport`] of the [`State`]. + pub fn viewport(&self) -> &Viewport { + &self.viewport + } + + /// Returns the version of the [`Viewport`] of the [`State`]. + /// + /// The version is incremented every time the [`Viewport`] changes. + pub fn viewport_version(&self) -> usize { + self.viewport_version + } + + /// Returns the physical [`Size`] of the [`Viewport`] of the [`State`]. + pub fn physical_size(&self) -> Size { + self.viewport.physical_size() + } + + /// Returns the logical [`Size`] of the [`Viewport`] of the [`State`]. + pub fn logical_size(&self) -> Size { + self.viewport.logical_size() + } + + /// Returns the current scale factor of the [`Viewport`] of the [`State`]. + pub fn scale_factor(&self) -> f64 { + self.viewport.scale_factor() + } + + /// Returns the current cursor position of the [`State`]. + pub fn cursor_position(&self) -> Point { + conversion::cursor_position( + self.cursor_position, + self.viewport.scale_factor(), + ) + } + + /// Returns the current keyboard modifiers of the [`State`]. + pub fn modifiers(&self) -> winit::event::ModifiersState { + self.modifiers + } + + /// Returns the current theme of the [`State`]. + pub fn theme(&self) -> &::Theme { + &self.theme + } + + /// Returns the current background [`Color`] of the [`State`]. + pub fn background_color(&self) -> Color { + self.appearance.background_color + } + + /// Returns the current text [`Color`] of the [`State`]. + pub fn text_color(&self) -> Color { + self.appearance.text_color + } + + /// Processes the provided window event and updates the [`State`] + /// accordingly. + pub fn update( + &mut self, + window: &Window, + event: &WindowEvent<'_>, + _debug: &mut Debug, + ) { + match event { + WindowEvent::Resized(new_size) => { + let size = Size::new(new_size.width, new_size.height); + + self.viewport = Viewport::with_physical_size( + size, + window.scale_factor() * self.scale_factor, + ); + + self.viewport_version = self.viewport_version.wrapping_add(1); + } + WindowEvent::ScaleFactorChanged { + scale_factor: new_scale_factor, + new_inner_size, + } => { + let size = + Size::new(new_inner_size.width, new_inner_size.height); + + self.viewport = Viewport::with_physical_size( + size, + new_scale_factor * self.scale_factor, + ); + + self.viewport_version = self.viewport_version.wrapping_add(1); + } + WindowEvent::CursorMoved { position, .. } + | WindowEvent::Touch(Touch { + location: position, .. + }) => { + self.cursor_position = *position; + } + WindowEvent::CursorLeft { .. } => { + // TODO: Encode cursor availability in the type-system + self.cursor_position = + winit::dpi::PhysicalPosition::new(-1.0, -1.0); + } + WindowEvent::ModifiersChanged(new_modifiers) => { + self.modifiers = *new_modifiers; + } + #[cfg(feature = "debug")] + WindowEvent::KeyboardInput { + input: + winit::event::KeyboardInput { + virtual_keycode: Some(winit::event::VirtualKeyCode::F12), + state: winit::event::ElementState::Pressed, + .. + }, + .. + } => _debug.toggle(), + _ => {} + } + } + + /// Synchronizes the [`State`] with its [`Application`] and its respective + /// window. + /// + /// Normally an [`Application`] should be synchronized with its [`State`] + /// and window after calling [`Application::update`]. + /// + /// [`Application::update`]: crate::Program::update + pub fn synchronize(&mut self, application: &A, window: &Window) { + // Update window title + let new_title = application.title(); + + if self.title != new_title { + window.set_title(&new_title); + + self.title = new_title; + } + + // Update scale factor + let new_scale_factor = application.scale_factor(); + + if self.scale_factor != new_scale_factor { + let size = window.inner_size(); + + self.viewport = Viewport::with_physical_size( + Size::new(size.width, size.height), + window.scale_factor() * new_scale_factor, + ); + + self.scale_factor = new_scale_factor; + } + + // Update theme and appearance + self.theme = application.theme(); + self.appearance = self.theme.appearance(application.style()); + } +} -- cgit From 8fdd5ee8b60e551088d4a18fb1d58b6c3e62ba7d Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 15 Jun 2022 20:38:51 -0300 Subject: Synchronize window list with `windows` method --- winit/src/multi_window/state.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 2d120ca1..009a3698 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -1,10 +1,12 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; -use crate::multi_window::Application; +use crate::multi_window::{Application, Event}; use crate::{Color, Debug, Point, Size, Viewport}; +use std::collections::HashMap; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; +use winit::event_loop::EventLoopProxy; use winit::window::Window; /// The state of a windowed [`Application`]. @@ -181,7 +183,23 @@ where /// and window after calling [`Application::update`]. /// /// [`Application::update`]: crate::Program::update - pub fn synchronize(&mut self, application: &A, window: &Window) { + pub fn synchronize( + &mut self, + application: &A, + windows: &HashMap, + proxy: &EventLoopProxy>, + ) { + let new_windows = application.windows(); + for (id, settings) in new_windows { + if !windows.contains_key(&id) { + proxy + .send_event(Event::NewWindow(id, settings)) + .expect("Failed to send message"); + } + } + + let window = windows.values().next().expect("No window found"); + // Update window title let new_title = application.title(); -- cgit From ec56c0686df1a200e37af951a3a8eca562c32a5c Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 21 Jun 2022 15:59:45 -0300 Subject: Introduce opaque `window::Id` type --- winit/src/multi_window/state.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 009a3698..dd2d25ce 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -1,6 +1,7 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; use crate::multi_window::{Application, Event}; +use crate::window; use crate::{Color, Debug, Point, Size, Viewport}; use std::collections::HashMap; @@ -186,7 +187,7 @@ where pub fn synchronize( &mut self, application: &A, - windows: &HashMap, + windows: &HashMap, proxy: &EventLoopProxy>, ) { let new_windows = application.windows(); -- cgit From 97914daaab477ce47a8329f07958332b5caa4ed0 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 12 Jul 2022 10:26:16 -0300 Subject: what is this --- winit/src/multi_window/state.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index dd2d25ce..d22de961 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -19,7 +19,7 @@ where title: String, scale_factor: f64, viewport: Viewport, - viewport_version: usize, + viewport_changed: bool, cursor_position: winit::dpi::PhysicalPosition, modifiers: winit::event::ModifiersState, theme: ::Theme, @@ -51,7 +51,7 @@ where title, scale_factor, viewport, - viewport_version: 0, + viewport_changed: false, // TODO: Encode cursor availability in the type-system cursor_position: winit::dpi::PhysicalPosition::new(-1.0, -1.0), modifiers: winit::event::ModifiersState::default(), @@ -66,11 +66,9 @@ where &self.viewport } - /// Returns the version of the [`Viewport`] of the [`State`]. - /// - /// The version is incremented every time the [`Viewport`] changes. - pub fn viewport_version(&self) -> usize { - self.viewport_version + /// TODO(derezzedex) + pub fn viewport_changed(&self) -> bool { + self.viewport_changed } /// Returns the physical [`Size`] of the [`Viewport`] of the [`State`]. @@ -133,7 +131,7 @@ where window.scale_factor() * self.scale_factor, ); - self.viewport_version = self.viewport_version.wrapping_add(1); + self.viewport_changed = true; } WindowEvent::ScaleFactorChanged { scale_factor: new_scale_factor, @@ -147,7 +145,7 @@ where new_scale_factor * self.scale_factor, ); - self.viewport_version = self.viewport_version.wrapping_add(1); + self.viewport_changed = true; } WindowEvent::CursorMoved { position, .. } | WindowEvent::Touch(Touch { -- cgit From 35331d0a41a53b8ff5c642b8274c7377ae6c6182 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 26 Jul 2022 16:46:12 -0300 Subject: Allow closing the window from user code --- winit/src/multi_window/state.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index d22de961..ae353e3b 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -189,6 +189,17 @@ where proxy: &EventLoopProxy>, ) { let new_windows = application.windows(); + + // Check for windows to close + for window_id in windows.keys() { + if !new_windows.iter().any(|(id, _)| id == window_id) { + proxy + .send_event(Event::CloseWindow(*window_id)) + .expect("Failed to send message"); + } + } + + // Check for windows to spawn for (id, settings) in new_windows { if !windows.contains_key(&id) { proxy -- cgit From 5e4e410b18eb744cf70ae1f18b9ef08611f59150 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 3 Nov 2022 14:53:05 -0300 Subject: remove `windows` method (use commands instead) --- winit/src/multi_window/state.rs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index ae353e3b..a7d51df4 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -1,13 +1,12 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; -use crate::multi_window::{Application, Event}; +use crate::multi_window::Application; use crate::window; use crate::{Color, Debug, Point, Size, Viewport}; use std::collections::HashMap; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; -use winit::event_loop::EventLoopProxy; use winit::window::Window; /// The state of a windowed [`Application`]. @@ -186,28 +185,7 @@ where &mut self, application: &A, windows: &HashMap, - proxy: &EventLoopProxy>, ) { - let new_windows = application.windows(); - - // Check for windows to close - for window_id in windows.keys() { - if !new_windows.iter().any(|(id, _)| id == window_id) { - proxy - .send_event(Event::CloseWindow(*window_id)) - .expect("Failed to send message"); - } - } - - // Check for windows to spawn - for (id, settings) in new_windows { - if !windows.contains_key(&id) { - proxy - .send_event(Event::NewWindow(id, settings)) - .expect("Failed to send message"); - } - } - let window = windows.values().next().expect("No window found"); // Update window title -- cgit From 942f1c91afb8257e289af8d0c229f74819f68361 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Mon, 2 Jan 2023 10:58:07 -0800 Subject: merged in iced master --- winit/src/multi_window/state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index a7d51df4..eebdcdf1 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -35,7 +35,7 @@ where let title = application.title(); let scale_factor = application.scale_factor(); let theme = application.theme(); - let appearance = theme.appearance(application.style()); + let appearance = theme.appearance(&application.style()); let viewport = { let physical_size = window.inner_size(); @@ -213,6 +213,6 @@ where // Update theme and appearance self.theme = application.theme(); - self.appearance = self.theme.appearance(application.style()); + self.appearance = self.theme.appearance(&application.style()); } } -- cgit From ec41918ec40bddaba81235372f1566da59fd09f2 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Thu, 5 Jan 2023 15:26:28 -0800 Subject: Implemented window title update functionality for multiwindow. --- winit/src/multi_window/state.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index eebdcdf1..7a598b98 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -4,7 +4,6 @@ use crate::multi_window::Application; use crate::window; use crate::{Color, Debug, Point, Size, Viewport}; -use std::collections::HashMap; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; use winit::window::Window; @@ -31,8 +30,8 @@ where ::Theme: application::StyleSheet, { /// Creates a new [`State`] for the provided [`Application`] and window. - pub fn new(application: &A, window: &Window) -> Self { - let title = application.title(); + pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self { + let title = application.title(window_id); let scale_factor = application.scale_factor(); let theme = application.theme(); let appearance = theme.appearance(&application.style()); @@ -65,7 +64,7 @@ where &self.viewport } - /// TODO(derezzedex) + /// Returns whether or not the viewport changed. pub fn viewport_changed(&self) -> bool { self.viewport_changed } @@ -184,12 +183,11 @@ where pub fn synchronize( &mut self, application: &A, - windows: &HashMap, + window_id: window::Id, + window: &Window, ) { - let window = windows.values().next().expect("No window found"); - // Update window title - let new_title = application.title(); + let new_title = application.title(window_id); if self.title != new_title { window.set_title(&new_title); -- cgit From 3e5d34f25fa07fa99f57b686bbde87d73b8ed548 Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Mon, 9 Jan 2023 10:19:12 -0800 Subject: Formatting --- winit/src/multi_window/state.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 7a598b98..2c2a4693 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -29,8 +29,12 @@ impl State where ::Theme: application::StyleSheet, { - /// Creates a new [`State`] for the provided [`Application`] and window. - pub fn new(application: &A, window_id: window::Id, window: &Window) -> Self { + /// Creates a new [`State`] for the provided [`Application`]'s window. + pub fn new( + application: &A, + window_id: window::Id, + window: &Window, + ) -> Self { let title = application.title(window_id); let scale_factor = application.scale_factor(); let theme = application.theme(); @@ -191,7 +195,6 @@ where if self.title != new_title { window.set_title(&new_title); - self.title = new_title; } -- cgit From 0a643287deece9234b64cc843a9f6ae3e6e4806e Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 18 Jan 2023 17:04:11 -0800 Subject: Added window::Id to multi_window application's scale_factor --- winit/src/multi_window/state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 2c2a4693..35c69924 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -36,7 +36,7 @@ where window: &Window, ) -> Self { let title = application.title(window_id); - let scale_factor = application.scale_factor(); + let scale_factor = application.scale_factor(window_id); let theme = application.theme(); let appearance = theme.appearance(&application.style()); @@ -199,7 +199,7 @@ where } // Update scale factor - let new_scale_factor = application.scale_factor(); + let new_scale_factor = application.scale_factor(window_id); if self.scale_factor != new_scale_factor { let size = window.inner_size(); -- cgit From e36daa6f937abd7cb2071fd8852a3c12263944ea Mon Sep 17 00:00:00 2001 From: bungoboingo Date: Tue, 28 Feb 2023 13:44:36 -0800 Subject: Removed glutin MW support and reverted glutin changes back to Iced master since it's being axed as we speak. --- winit/src/multi_window/state.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 35c69924..a7e65de7 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -8,7 +8,7 @@ use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; use winit::window::Window; -/// The state of a windowed [`Application`]. +/// The state of a multi-windowed [`Application`]. #[allow(missing_debug_implementations)] pub struct State where @@ -29,7 +29,7 @@ impl State where ::Theme: application::StyleSheet, { - /// Creates a new [`State`] for the provided [`Application`]'s window. + /// Creates a new [`State`] for the provided [`Application`]'s `window`. pub fn new( application: &A, window_id: window::Id, @@ -116,8 +116,7 @@ where self.appearance.text_color } - /// Processes the provided window event and updates the [`State`] - /// accordingly. + /// Processes the provided window event and updates the [`State`] accordingly. pub fn update( &mut self, window: &Window, -- cgit From 8ba18430800142965549077373e2a45d0a3429a1 Mon Sep 17 00:00:00 2001 From: Bingus Date: Mon, 13 Mar 2023 14:16:45 -0700 Subject: Code cleanup, clearer comments + removed some unnecessary dupe; Removed `Frames` struct return for `window::frames()` since we are just redrawing every window anyways; Interface dropping; --- winit/src/multi_window/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index a7e65de7..d0e442d0 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -179,7 +179,7 @@ where /// Synchronizes the [`State`] with its [`Application`] and its respective /// window. /// - /// Normally an [`Application`] should be synchronized with its [`State`] + /// Normally, an [`Application`] should be synchronized with its [`State`] /// and window after calling [`Application::update`]. /// /// [`Application::update`]: crate::Program::update -- cgit From 41836dd80d0534608e7aedfbf2319c540a23de1a Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 15 Mar 2023 18:20:38 -0700 Subject: Added per-window theme support. --- winit/src/multi_window/state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index d0e442d0..54a114ad 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -37,7 +37,7 @@ where ) -> Self { let title = application.title(window_id); let scale_factor = application.scale_factor(window_id); - let theme = application.theme(); + let theme = application.theme(window_id); let appearance = theme.appearance(&application.style()); let viewport = { @@ -212,7 +212,7 @@ where } // Update theme and appearance - self.theme = application.theme(); + self.theme = application.theme(window_id); self.appearance = self.theme.appearance(&application.style()); } } -- cgit From d53ccc857da4d4cda769904342aeb5a82a64f146 Mon Sep 17 00:00:00 2001 From: Bingus Date: Wed, 12 Jul 2023 19:21:05 -0700 Subject: refactored window storage; new helper window events (Destroyed, Created); clippy + fmt; --- winit/src/multi_window/state.rs | 96 +++++++++++++-------- winit/src/multi_window/windows.rs | 170 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+), 36 deletions(-) create mode 100644 winit/src/multi_window/windows.rs (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index 54a114ad..f2741c3c 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -1,33 +1,50 @@ -use crate::application::{self, StyleSheet as _}; use crate::conversion; +use crate::core; +use crate::core::{mouse, window}; +use crate::core::{Color, Size}; +use crate::graphics::Viewport; use crate::multi_window::Application; -use crate::window; -use crate::{Color, Debug, Point, Size, Viewport}; +use crate::style::application; +use std::fmt::{Debug, Formatter}; -use std::marker::PhantomData; +use iced_style::application::StyleSheet; use winit::event::{Touch, WindowEvent}; use winit::window::Window; /// The state of a multi-windowed [`Application`]. -#[allow(missing_debug_implementations)] pub struct State where - ::Theme: application::StyleSheet, + ::Theme: application::StyleSheet, { title: String, scale_factor: f64, viewport: Viewport, - viewport_changed: bool, - cursor_position: winit::dpi::PhysicalPosition, + viewport_version: usize, + cursor_position: Option>, modifiers: winit::event::ModifiersState, - theme: ::Theme, + theme: ::Theme, appearance: application::Appearance, - application: PhantomData, +} + +impl Debug for State +where + ::Theme: application::StyleSheet, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("multi_window::State") + .field("title", &self.title) + .field("scale_factor", &self.scale_factor) + .field("viewport", &self.viewport) + .field("viewport_version", &self.viewport_version) + .field("cursor_position", &self.cursor_position) + .field("appearance", &self.appearance) + .finish() + } } impl State where - ::Theme: application::StyleSheet, + ::Theme: application::StyleSheet, { /// Creates a new [`State`] for the provided [`Application`]'s `window`. pub fn new( @@ -53,13 +70,11 @@ where title, scale_factor, viewport, - viewport_changed: false, - // TODO: Encode cursor availability in the type-system - cursor_position: winit::dpi::PhysicalPosition::new(-1.0, -1.0), + viewport_version: 0, + cursor_position: None, modifiers: winit::event::ModifiersState::default(), theme, appearance, - application: PhantomData, } } @@ -68,9 +83,11 @@ where &self.viewport } - /// Returns whether or not the viewport changed. - pub fn viewport_changed(&self) -> bool { - self.viewport_changed + /// Returns the version of the [`Viewport`] of the [`State`]. + /// + /// The version is incremented every time the [`Viewport`] changes. + pub fn viewport_version(&self) -> usize { + self.viewport_version } /// Returns the physical [`Size`] of the [`Viewport`] of the [`State`]. @@ -89,11 +106,16 @@ where } /// Returns the current cursor position of the [`State`]. - pub fn cursor_position(&self) -> Point { - conversion::cursor_position( - self.cursor_position, - self.viewport.scale_factor(), - ) + pub fn cursor(&self) -> mouse::Cursor { + self.cursor_position + .map(|cursor_position| { + conversion::cursor_position( + cursor_position, + self.viewport.scale_factor(), + ) + }) + .map(mouse::Cursor::Available) + .unwrap_or(mouse::Cursor::Unavailable) } /// Returns the current keyboard modifiers of the [`State`]. @@ -102,7 +124,7 @@ where } /// Returns the current theme of the [`State`]. - pub fn theme(&self) -> &::Theme { + pub fn theme(&self) -> &::Theme { &self.theme } @@ -121,7 +143,7 @@ where &mut self, window: &Window, event: &WindowEvent<'_>, - _debug: &mut Debug, + _debug: &mut crate::runtime::Debug, ) { match event { WindowEvent::Resized(new_size) => { @@ -132,7 +154,7 @@ where window.scale_factor() * self.scale_factor, ); - self.viewport_changed = true; + self.viewport_version = self.viewport_version.wrapping_add(1); } WindowEvent::ScaleFactorChanged { scale_factor: new_scale_factor, @@ -146,18 +168,16 @@ where new_scale_factor * self.scale_factor, ); - self.viewport_changed = true; + self.viewport_version = self.viewport_version.wrapping_add(1); } WindowEvent::CursorMoved { position, .. } | WindowEvent::Touch(Touch { location: position, .. }) => { - self.cursor_position = *position; + self.cursor_position = Some(*position); } WindowEvent::CursorLeft { .. } => { - // TODO: Encode cursor availability in the type-system - self.cursor_position = - winit::dpi::PhysicalPosition::new(-1.0, -1.0); + self.cursor_position = None; } WindowEvent::ModifiersChanged(new_modifiers) => { self.modifiers = *new_modifiers; @@ -197,16 +217,20 @@ where self.title = new_title; } - // Update scale factor + // Update scale factor and size let new_scale_factor = application.scale_factor(window_id); + let new_size = window.inner_size(); + let current_size = self.viewport.physical_size(); - if self.scale_factor != new_scale_factor { - let size = window.inner_size(); - + if self.scale_factor != new_scale_factor + || (current_size.width, current_size.height) + != (new_size.width, new_size.height) + { self.viewport = Viewport::with_physical_size( - Size::new(size.width, size.height), + Size::new(new_size.width, new_size.height), window.scale_factor() * new_scale_factor, ); + self.viewport_version = self.viewport_version.wrapping_add(1); self.scale_factor = new_scale_factor; } diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs new file mode 100644 index 00000000..7b63defa --- /dev/null +++ b/winit/src/multi_window/windows.rs @@ -0,0 +1,170 @@ +use crate::core::{window, Size}; +use crate::multi_window::{Application, State}; +use iced_graphics::Compositor; +use iced_style::application::StyleSheet; +use std::fmt::{Debug, Formatter}; +use winit::monitor::MonitorHandle; + +pub struct Windows +where + ::Theme: StyleSheet, + C: Compositor, +{ + pub ids: Vec, + pub raw: Vec, + pub states: Vec>, + pub viewport_versions: Vec, + pub surfaces: Vec, + pub renderers: Vec, + pub pending_destroy: Vec<(window::Id, winit::window::WindowId)>, +} + +impl Debug for Windows +where + ::Theme: StyleSheet, + C: Compositor, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Windows") + .field("ids", &self.ids) + .field( + "raw", + &self + .raw + .iter() + .map(|raw| raw.id()) + .collect::>(), + ) + .field("states", &self.states) + .field("viewport_versions", &self.viewport_versions) + .finish() + } +} + +impl Windows +where + ::Theme: StyleSheet, + C: Compositor, +{ + /// Creates a new [`Windows`] with a single `window::Id::MAIN` window. + pub fn new( + application: &A, + compositor: &mut C, + renderer: A::Renderer, + main: winit::window::Window, + ) -> Self { + let state = State::new(application, window::Id::MAIN, &main); + let viewport_version = state.viewport_version(); + let physical_size = state.physical_size(); + let surface = compositor.create_surface( + &main, + physical_size.width, + physical_size.height, + ); + + Self { + ids: vec![window::Id::MAIN], + raw: vec![main], + states: vec![state], + viewport_versions: vec![viewport_version], + surfaces: vec![surface], + renderers: vec![renderer], + pending_destroy: vec![], + } + } + + /// Adds a new window to [`Windows`]. Returns the size of the newly created window in logical + /// pixels & the index of the window within [`Windows`]. + pub fn add( + &mut self, + application: &A, + compositor: &mut C, + id: window::Id, + window: winit::window::Window, + ) -> (Size, usize) { + let state = State::new(application, id, &window); + let window_size = state.logical_size(); + let viewport_version = state.viewport_version(); + let physical_size = state.physical_size(); + let surface = compositor.create_surface( + &window, + physical_size.width, + physical_size.height, + ); + let renderer = compositor.renderer(); + + self.ids.push(id); + self.raw.push(window); + self.states.push(state); + self.viewport_versions.push(viewport_version); + self.surfaces.push(surface); + self.renderers.push(renderer); + + (window_size, self.ids.len() - 1) + } + + pub fn is_empty(&self) -> bool { + self.ids.is_empty() + } + + pub fn main(&self) -> &winit::window::Window { + &self.raw[0] + } + + pub fn index_from_raw(&self, id: winit::window::WindowId) -> usize { + self.raw + .iter() + .position(|window| window.id() == id) + .expect("No raw window in multi_window::Windows") + } + + pub fn index_from_id(&self, id: window::Id) -> usize { + self.ids + .iter() + .position(|window_id| *window_id == id) + .expect("No window in multi_window::Windows") + } + + pub fn last_monitor(&self) -> Option { + self.raw.last().and_then(|w| w.current_monitor()) + } + + pub fn last(&self) -> usize { + self.ids.len() - 1 + } + + pub fn with_raw(&self, id: window::Id) -> &winit::window::Window { + let i = self.index_from_id(id); + &self.raw[i] + } + + /// Deletes the window with `id` from [`Windows`]. Returns the index that the window had. + pub fn delete(&mut self, id: window::Id) -> usize { + let i = self.index_from_id(id); + + let id = self.ids.remove(i); + let window = self.raw.remove(i); + let _ = self.states.remove(i); + let _ = self.viewport_versions.remove(i); + let _ = self.surfaces.remove(i); + + self.pending_destroy.push((id, window.id())); + + i + } + + /// Gets the winit `window` that is pending to be destroyed if it exists. + pub fn get_pending_destroy( + &mut self, + window: winit::window::WindowId, + ) -> window::Id { + let i = self + .pending_destroy + .iter() + .position(|(_, window_id)| window == *window_id) + .unwrap(); + + let (id, _) = self.pending_destroy.remove(i); + id + } +} -- cgit From 83c7870c569a2976923ee6243a19813094d44673 Mon Sep 17 00:00:00 2001 From: Bingus Date: Mon, 24 Jul 2023 14:32:59 -0700 Subject: Moved `exit_on_close_request` to window settings. This now controls whether each INDIVIDUAL window should close on CloseRequested events. --- winit/src/multi_window/windows.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs index 7b63defa..1f606b31 100644 --- a/winit/src/multi_window/windows.rs +++ b/winit/src/multi_window/windows.rs @@ -14,6 +14,7 @@ where pub raw: Vec, pub states: Vec>, pub viewport_versions: Vec, + pub exit_on_close_requested: Vec, pub surfaces: Vec, pub renderers: Vec, pub pending_destroy: Vec<(window::Id, winit::window::WindowId)>, @@ -52,6 +53,7 @@ where compositor: &mut C, renderer: A::Renderer, main: winit::window::Window, + exit_on_close_requested: bool, ) -> Self { let state = State::new(application, window::Id::MAIN, &main); let viewport_version = state.viewport_version(); @@ -67,6 +69,7 @@ where raw: vec![main], states: vec![state], viewport_versions: vec![viewport_version], + exit_on_close_requested: vec![exit_on_close_requested], surfaces: vec![surface], renderers: vec![renderer], pending_destroy: vec![], @@ -81,6 +84,7 @@ where compositor: &mut C, id: window::Id, window: winit::window::Window, + exit_on_close_requested: bool, ) -> (Size, usize) { let state = State::new(application, id, &window); let window_size = state.logical_size(); @@ -96,6 +100,7 @@ where self.ids.push(id); self.raw.push(window); self.states.push(state); + self.exit_on_close_requested.push(exit_on_close_requested); self.viewport_versions.push(viewport_version); self.surfaces.push(surface); self.renderers.push(renderer); @@ -145,6 +150,7 @@ where let id = self.ids.remove(i); let window = self.raw.remove(i); let _ = self.states.remove(i); + let _ = self.exit_on_close_requested.remove(i); let _ = self.viewport_versions.remove(i); let _ = self.surfaces.remove(i); @@ -167,4 +173,24 @@ where let (id, _) = self.pending_destroy.remove(i); id } + + /// Returns the windows that need to be requested to closed, and also the windows that can be + /// closed immediately. + pub fn partition_close_requests(&self) -> (Vec, Vec) { + self.exit_on_close_requested.iter().enumerate().fold( + (vec![], vec![]), + |(mut close_immediately, mut needs_request_closed), + (i, close)| { + let id = self.ids[i]; + + if *close { + close_immediately.push(id); + } else { + needs_request_closed.push(id); + } + + (close_immediately, needs_request_closed) + }, + ) + } } -- cgit From 9b34b2ac19a8fdd424581d160bc702e096a2b46a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 22:33:41 +0100 Subject: Run `cargo fmt` --- winit/src/multi_window/windows.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs index 1f606b31..6846abb3 100644 --- a/winit/src/multi_window/windows.rs +++ b/winit/src/multi_window/windows.rs @@ -176,11 +176,12 @@ where /// Returns the windows that need to be requested to closed, and also the windows that can be /// closed immediately. - pub fn partition_close_requests(&self) -> (Vec, Vec) { + pub fn partition_close_requests( + &self, + ) -> (Vec, Vec) { self.exit_on_close_requested.iter().enumerate().fold( (vec![], vec![]), - |(mut close_immediately, mut needs_request_closed), - (i, close)| { + |(mut close_immediately, mut needs_request_closed), (i, close)| { let id = self.ids[i]; if *close { -- cgit From 7def3ee38a3f0f24a331d722b09f325fc9584625 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 22:37:54 +0100 Subject: Fix `clippy` lints --- winit/src/multi_window/windows.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs index 6846abb3..a4841a45 100644 --- a/winit/src/multi_window/windows.rs +++ b/winit/src/multi_window/windows.rs @@ -1,10 +1,12 @@ use crate::core::{window, Size}; +use crate::graphics::Compositor; use crate::multi_window::{Application, State}; -use iced_graphics::Compositor; -use iced_style::application::StyleSheet; -use std::fmt::{Debug, Formatter}; +use crate::style::application::StyleSheet; + use winit::monitor::MonitorHandle; +use std::fmt::{Debug, Formatter}; + pub struct Windows where ::Theme: StyleSheet, @@ -33,7 +35,7 @@ where &self .raw .iter() - .map(|raw| raw.id()) + .map(winit::window::Window::id) .collect::>(), ) .field("states", &self.states) @@ -131,7 +133,9 @@ where } pub fn last_monitor(&self) -> Option { - self.raw.last().and_then(|w| w.current_monitor()) + self.raw + .last() + .and_then(winit::window::Window::current_monitor) } pub fn last(&self) -> usize { -- cgit From 6740c2c5d6b24399dab1343abdfec5daf4b03c98 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 29 Nov 2023 22:46:47 +0100 Subject: Fix broken intra-doc links --- winit/src/multi_window/state.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index f2741c3c..e9a9f91a 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -200,9 +200,7 @@ where /// window. /// /// Normally, an [`Application`] should be synchronized with its [`State`] - /// and window after calling [`Application::update`]. - /// - /// [`Application::update`]: crate::Program::update + /// and window after calling [`State::update`]. pub fn synchronize( &mut self, application: &A, -- cgit From b152ecda63238136f77b6eda3c582fa1eff99737 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 2 Dec 2023 20:49:47 +0100 Subject: Separate `Compositor::new` from `Compositor::create_renderer` --- winit/src/multi_window/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs index a4841a45..5a33b7b4 100644 --- a/winit/src/multi_window/windows.rs +++ b/winit/src/multi_window/windows.rs @@ -97,7 +97,7 @@ where physical_size.width, physical_size.height, ); - let renderer = compositor.renderer(); + let renderer = compositor.create_renderer(); self.ids.push(id); self.raw.push(window); -- cgit From 5c5e7653bed248ba63faa6563e4d673e4441415e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 2 Dec 2023 22:26:01 +0100 Subject: Refactor `Windows` abstraction into `WindowManager` --- winit/src/multi_window/state.rs | 4 +- winit/src/multi_window/window_manager.rs | 156 ++++++++++++++++++++++++ winit/src/multi_window/windows.rs | 201 ------------------------------- 3 files changed, 158 insertions(+), 203 deletions(-) create mode 100644 winit/src/multi_window/window_manager.rs delete mode 100644 winit/src/multi_window/windows.rs (limited to 'winit/src/multi_window') diff --git a/winit/src/multi_window/state.rs b/winit/src/multi_window/state.rs index e9a9f91a..03da5ad7 100644 --- a/winit/src/multi_window/state.rs +++ b/winit/src/multi_window/state.rs @@ -19,7 +19,7 @@ where title: String, scale_factor: f64, viewport: Viewport, - viewport_version: usize, + viewport_version: u64, cursor_position: Option>, modifiers: winit::event::ModifiersState, theme: ::Theme, @@ -86,7 +86,7 @@ where /// Returns the version of the [`Viewport`] of the [`State`]. /// /// The version is incremented every time the [`Viewport`] changes. - pub fn viewport_version(&self) -> usize { + pub fn viewport_version(&self) -> u64 { self.viewport_version } diff --git a/winit/src/multi_window/window_manager.rs b/winit/src/multi_window/window_manager.rs new file mode 100644 index 00000000..d54156e7 --- /dev/null +++ b/winit/src/multi_window/window_manager.rs @@ -0,0 +1,156 @@ +use crate::core::mouse; +use crate::core::window::Id; +use crate::core::{Point, Size}; +use crate::graphics::Compositor; +use crate::multi_window::{Application, State}; +use crate::style::application::StyleSheet; + +use std::collections::BTreeMap; +use winit::monitor::MonitorHandle; + +#[allow(missing_debug_implementations)] +pub struct WindowManager +where + ::Theme: StyleSheet, + C: Compositor, +{ + aliases: BTreeMap, + entries: BTreeMap>, +} + +impl WindowManager +where + A: Application, + C: Compositor, + ::Theme: StyleSheet, +{ + pub fn new() -> Self { + Self { + aliases: BTreeMap::new(), + entries: BTreeMap::new(), + } + } + + pub fn insert( + &mut self, + id: Id, + window: winit::window::Window, + application: &A, + compositor: &mut C, + exit_on_close_request: bool, + ) -> &mut Window { + let state = State::new(application, id, &window); + let viewport_version = state.viewport_version(); + let physical_size = state.physical_size(); + let surface = compositor.create_surface( + &window, + physical_size.width, + physical_size.height, + ); + let renderer = compositor.create_renderer(); + + let _ = self.aliases.insert(window.id(), id); + + let _ = self.entries.insert( + id, + Window { + raw: window, + state, + viewport_version, + exit_on_close_request, + surface, + renderer, + mouse_interaction: mouse::Interaction::Idle, + }, + ); + + self.entries + .get_mut(&id) + .expect("Get window that was just inserted") + } + + pub fn is_empty(&self) -> bool { + self.entries.is_empty() + } + + pub fn iter_mut( + &mut self, + ) -> impl Iterator)> { + self.entries.iter_mut().map(|(k, v)| (*k, v)) + } + + pub fn get_mut(&mut self, id: Id) -> Option<&mut Window> { + self.entries.get_mut(&id) + } + + pub fn get_mut_alias( + &mut self, + id: winit::window::WindowId, + ) -> Option<(Id, &mut Window)> { + let id = self.aliases.get(&id).copied()?; + + Some((id, self.get_mut(id)?)) + } + + pub fn last_monitor(&self) -> Option { + self.entries.values().last()?.raw.current_monitor() + } + + pub fn remove(&mut self, id: Id) -> Option> { + let window = self.entries.remove(&id)?; + let _ = self.aliases.remove(&window.raw.id()); + + Some(window) + } +} + +impl Default for WindowManager +where + A: Application, + C: Compositor, + ::Theme: StyleSheet, +{ + fn default() -> Self { + Self::new() + } +} + +#[allow(missing_debug_implementations)] +pub struct Window +where + A: Application, + C: Compositor, + ::Theme: StyleSheet, +{ + pub raw: winit::window::Window, + pub state: State, + pub viewport_version: u64, + pub exit_on_close_request: bool, + pub mouse_interaction: mouse::Interaction, + pub surface: C::Surface, + pub renderer: A::Renderer, +} + +impl Window +where + A: Application, + C: Compositor, + ::Theme: StyleSheet, +{ + pub fn position(&self) -> Option { + self.raw + .inner_position() + .ok() + .map(|position| position.to_logical(self.raw.scale_factor())) + .map(|position| Point { + x: position.x, + y: position.y, + }) + } + + pub fn size(&self) -> Size { + let size = self.raw.inner_size().to_logical(self.raw.scale_factor()); + + Size::new(size.width, size.height) + } +} diff --git a/winit/src/multi_window/windows.rs b/winit/src/multi_window/windows.rs deleted file mode 100644 index 5a33b7b4..00000000 --- a/winit/src/multi_window/windows.rs +++ /dev/null @@ -1,201 +0,0 @@ -use crate::core::{window, Size}; -use crate::graphics::Compositor; -use crate::multi_window::{Application, State}; -use crate::style::application::StyleSheet; - -use winit::monitor::MonitorHandle; - -use std::fmt::{Debug, Formatter}; - -pub struct Windows -where - ::Theme: StyleSheet, - C: Compositor, -{ - pub ids: Vec, - pub raw: Vec, - pub states: Vec>, - pub viewport_versions: Vec, - pub exit_on_close_requested: Vec, - pub surfaces: Vec, - pub renderers: Vec, - pub pending_destroy: Vec<(window::Id, winit::window::WindowId)>, -} - -impl Debug for Windows -where - ::Theme: StyleSheet, - C: Compositor, -{ - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("Windows") - .field("ids", &self.ids) - .field( - "raw", - &self - .raw - .iter() - .map(winit::window::Window::id) - .collect::>(), - ) - .field("states", &self.states) - .field("viewport_versions", &self.viewport_versions) - .finish() - } -} - -impl Windows -where - ::Theme: StyleSheet, - C: Compositor, -{ - /// Creates a new [`Windows`] with a single `window::Id::MAIN` window. - pub fn new( - application: &A, - compositor: &mut C, - renderer: A::Renderer, - main: winit::window::Window, - exit_on_close_requested: bool, - ) -> Self { - let state = State::new(application, window::Id::MAIN, &main); - let viewport_version = state.viewport_version(); - let physical_size = state.physical_size(); - let surface = compositor.create_surface( - &main, - physical_size.width, - physical_size.height, - ); - - Self { - ids: vec![window::Id::MAIN], - raw: vec![main], - states: vec![state], - viewport_versions: vec![viewport_version], - exit_on_close_requested: vec![exit_on_close_requested], - surfaces: vec![surface], - renderers: vec![renderer], - pending_destroy: vec![], - } - } - - /// Adds a new window to [`Windows`]. Returns the size of the newly created window in logical - /// pixels & the index of the window within [`Windows`]. - pub fn add( - &mut self, - application: &A, - compositor: &mut C, - id: window::Id, - window: winit::window::Window, - exit_on_close_requested: bool, - ) -> (Size, usize) { - let state = State::new(application, id, &window); - let window_size = state.logical_size(); - let viewport_version = state.viewport_version(); - let physical_size = state.physical_size(); - let surface = compositor.create_surface( - &window, - physical_size.width, - physical_size.height, - ); - let renderer = compositor.create_renderer(); - - self.ids.push(id); - self.raw.push(window); - self.states.push(state); - self.exit_on_close_requested.push(exit_on_close_requested); - self.viewport_versions.push(viewport_version); - self.surfaces.push(surface); - self.renderers.push(renderer); - - (window_size, self.ids.len() - 1) - } - - pub fn is_empty(&self) -> bool { - self.ids.is_empty() - } - - pub fn main(&self) -> &winit::window::Window { - &self.raw[0] - } - - pub fn index_from_raw(&self, id: winit::window::WindowId) -> usize { - self.raw - .iter() - .position(|window| window.id() == id) - .expect("No raw window in multi_window::Windows") - } - - pub fn index_from_id(&self, id: window::Id) -> usize { - self.ids - .iter() - .position(|window_id| *window_id == id) - .expect("No window in multi_window::Windows") - } - - pub fn last_monitor(&self) -> Option { - self.raw - .last() - .and_then(winit::window::Window::current_monitor) - } - - pub fn last(&self) -> usize { - self.ids.len() - 1 - } - - pub fn with_raw(&self, id: window::Id) -> &winit::window::Window { - let i = self.index_from_id(id); - &self.raw[i] - } - - /// Deletes the window with `id` from [`Windows`]. Returns the index that the window had. - pub fn delete(&mut self, id: window::Id) -> usize { - let i = self.index_from_id(id); - - let id = self.ids.remove(i); - let window = self.raw.remove(i); - let _ = self.states.remove(i); - let _ = self.exit_on_close_requested.remove(i); - let _ = self.viewport_versions.remove(i); - let _ = self.surfaces.remove(i); - - self.pending_destroy.push((id, window.id())); - - i - } - - /// Gets the winit `window` that is pending to be destroyed if it exists. - pub fn get_pending_destroy( - &mut self, - window: winit::window::WindowId, - ) -> window::Id { - let i = self - .pending_destroy - .iter() - .position(|(_, window_id)| window == *window_id) - .unwrap(); - - let (id, _) = self.pending_destroy.remove(i); - id - } - - /// Returns the windows that need to be requested to closed, and also the windows that can be - /// closed immediately. - pub fn partition_close_requests( - &self, - ) -> (Vec, Vec) { - self.exit_on_close_requested.iter().enumerate().fold( - (vec![], vec![]), - |(mut close_immediately, mut needs_request_closed), (i, close)| { - let id = self.ids[i]; - - if *close { - close_immediately.push(id); - } else { - needs_request_closed.push(id); - } - - (close_immediately, needs_request_closed) - }, - ) - } -} -- cgit