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.rs | 23 +++++++++++++---------- winit/src/multi_window/state.rs | 3 ++- winit/src/window.rs | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'winit/src') diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 900ee92a..14be4de3 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -9,6 +9,7 @@ use crate::mouse; use crate::renderer; use crate::settings; use crate::widget::operation; +use crate::window; use crate::{ Command, Debug, Element, Error, Executor, Proxy, Renderer, Runtime, Settings, Size, Subscription, @@ -17,7 +18,6 @@ use crate::{ use iced_futures::futures::channel::mpsc; use iced_futures::futures::{self, FutureExt}; use iced_graphics::compositor; -use iced_graphics::window; use iced_native::user_interface::{self, UserInterface}; pub use iced_native::application::{Appearance, StyleSheet}; @@ -37,9 +37,9 @@ pub enum Event { /// TODO(derezzedex) // Create a wrapper variant of `window::Event` type instead // (maybe we should also allow users to listen/react to those internal messages?) - NewWindow(usize, settings::Window), + NewWindow(window::Id, settings::Window), /// TODO(derezzedex) - WindowCreated(usize, winit::window::Window), + WindowCreated(window::Id, winit::window::Window), } /// An interactive, native cross-platform application. @@ -66,6 +66,9 @@ where /// The type of __messages__ your [`Program`] will produce. type Message: std::fmt::Debug + Send; + /// TODO(derezzedex) + fn windows(&self) -> Vec<(window::Id, settings::Window)>; + /// Handles a __message__ and updates the state of the [`Program`]. /// /// This is where you define your __update logic__. All the __messages__, @@ -150,7 +153,7 @@ pub fn run( where A: Application + 'static, E: Executor + 'static, - C: window::Compositor + 'static, + C: iced_graphics::window::Compositor + 'static, ::Theme: StyleSheet, { use futures::task; @@ -188,8 +191,8 @@ where .build(&event_loop) .map_err(Error::WindowCreationFailed)?; - let windows: HashMap = - HashMap::from([(0usize, window)]); + let windows: HashMap = + HashMap::from([(window::Id::new(0usize), window)]); let window = windows.values().next().expect("No window found"); #[cfg(target_arch = "wasm32")] @@ -287,12 +290,12 @@ async fn run_instance( winit::event::Event<'_, Event>, >, init_command: Command, - mut windows: HashMap, + mut windows: HashMap, exit_on_close_request: bool, ) where A: Application + 'static, E: Executor + 'static, - C: window::Compositor + 'static, + C: iced_graphics::window::Compositor + 'static, ::Theme: StyleSheet, { use iced_futures::futures::stream::StreamExt; @@ -629,7 +632,7 @@ pub fn update( proxy: &mut winit::event_loop::EventLoopProxy>, debug: &mut Debug, messages: &mut Vec, - windows: &HashMap, + windows: &HashMap, graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where ::Theme: StyleSheet, @@ -671,7 +674,7 @@ pub fn run_command( clipboard: &mut Clipboard, proxy: &mut winit::event_loop::EventLoopProxy>, debug: &mut Debug, - windows: &HashMap, + windows: &HashMap, _graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where A: Application, 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(); diff --git a/winit/src/window.rs b/winit/src/window.rs index 89db3262..f2c7037a 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -2,7 +2,7 @@ use crate::command::{self, Command}; use iced_native::window; -pub use window::{Event, Mode, UserAttention}; +pub use window::{Id, Event, Mode, UserAttention}; /// Closes the current window and exits the application. pub fn close() -> Command { -- cgit