summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--native/src/window.rs2
-rw-r--r--native/src/window/id.rs16
-rw-r--r--src/multi_window/application.rs14
-rw-r--r--winit/src/multi_window.rs23
-rw-r--r--winit/src/multi_window/state.rs3
-rw-r--r--winit/src/window.rs2
6 files changed, 48 insertions, 12 deletions
diff --git a/native/src/window.rs b/native/src/window.rs
index 1b97e655..dc9e2d66 100644
--- a/native/src/window.rs
+++ b/native/src/window.rs
@@ -1,10 +1,12 @@
//! Build window-based GUI applications.
mod action;
mod event;
+mod id;
mod mode;
mod user_attention;
pub use action::Action;
pub use event::Event;
+pub use id::Id;
pub use mode::Mode;
pub use user_attention::UserAttention;
diff --git a/native/src/window/id.rs b/native/src/window/id.rs
new file mode 100644
index 00000000..56496aaa
--- /dev/null
+++ b/native/src/window/id.rs
@@ -0,0 +1,16 @@
+use std::collections::hash_map::DefaultHasher;
+use std::hash::{Hash, Hasher};
+
+#[derive(Debug, PartialEq, Eq, Hash)]
+/// TODO(derezzedex)
+pub struct Id(u64);
+
+impl Id {
+ /// TODO(derezzedex)
+ pub fn new(id: impl Hash) -> Id {
+ let mut hasher = DefaultHasher::new();
+ id.hash(&mut hasher);
+
+ Id(hasher.finish())
+ }
+}
diff --git a/src/multi_window/application.rs b/src/multi_window/application.rs
index fa0c15b1..6b3f4676 100644
--- a/src/multi_window/application.rs
+++ b/src/multi_window/application.rs
@@ -1,3 +1,4 @@
+use crate::window;
use crate::{Command, Element, Executor, Settings, Subscription};
pub use iced_native::application::{Appearance, StyleSheet};
@@ -45,6 +46,9 @@ pub trait Application: Sized {
/// title of your application when necessary.
fn title(&self) -> String;
+ /// TODO(derezzedex)
+ fn windows(&self) -> Vec<(window::Id, window::Settings)>;
+
/// Handles a __message__ and updates the state of the [`Application`].
///
/// This is where you define your __update logic__. All the __messages__,
@@ -160,6 +164,16 @@ where
self.0.title()
}
+ fn windows(&self) -> Vec<(window::Id, iced_winit::settings::Window)> {
+ self.0
+ .windows()
+ .into_iter()
+ .map(|(id, settings)| {
+ (id, iced_winit::settings::Window::from(settings))
+ })
+ .collect()
+ }
+
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
self.0.update(message)
}
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<Message> {
/// 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<A, E, C>(
where
A: Application + 'static,
E: Executor + 'static,
- C: window::Compositor<Renderer = A::Renderer> + 'static,
+ C: iced_graphics::window::Compositor<Renderer = A::Renderer> + 'static,
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
{
use futures::task;
@@ -188,8 +191,8 @@ where
.build(&event_loop)
.map_err(Error::WindowCreationFailed)?;
- let windows: HashMap<usize, winit::window::Window> =
- HashMap::from([(0usize, window)]);
+ let windows: HashMap<window::Id, winit::window::Window> =
+ 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<A, E, C>(
winit::event::Event<'_, Event<A::Message>>,
>,
init_command: Command<A::Message>,
- mut windows: HashMap<usize, winit::window::Window>,
+ mut windows: HashMap<window::Id, winit::window::Window>,
exit_on_close_request: bool,
) where
A: Application + 'static,
E: Executor + 'static,
- C: window::Compositor<Renderer = A::Renderer> + 'static,
+ C: iced_graphics::window::Compositor<Renderer = A::Renderer> + 'static,
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
{
use iced_futures::futures::stream::StreamExt;
@@ -629,7 +632,7 @@ pub fn update<A: Application, E: Executor>(
proxy: &mut winit::event_loop::EventLoopProxy<Event<A::Message>>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
- windows: &HashMap<usize, winit::window::Window>,
+ windows: &HashMap<window::Id, winit::window::Window>,
graphics_info: impl FnOnce() -> compositor::Information + Copy,
) where
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
@@ -671,7 +674,7 @@ pub fn run_command<A, E>(
clipboard: &mut Clipboard,
proxy: &mut winit::event_loop::EventLoopProxy<Event<A::Message>>,
debug: &mut Debug,
- windows: &HashMap<usize, winit::window::Window>,
+ windows: &HashMap<window::Id, winit::window::Window>,
_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<usize, Window>,
+ windows: &HashMap<window::Id, Window>,
proxy: &EventLoopProxy<Event<A::Message>>,
) {
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<Message>() -> Command<Message> {