-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: multi-window support #1439
Conversation
Instead of creating a separate `multi_window::Program`, the new `multi_window::Application` unifies both traits
events internaly
d0ed082
to
3969b8d
Compare
3969b8d
to
ba71f99
Compare
I found a bug on the |
Another bug on both Here is the modified example: diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs
index 88ddf46f..717bcc9c 100644
--- a/examples/multi_window/src/main.rs
+++ b/examples/multi_window/src/main.rs
@@ -60,18 +60,32 @@ impl Application for Example {
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
- let (panes, _) =
- pane_grid::State::new(Pane::new(0, pane_grid::Axis::Horizontal));
- let window = Window {
- panes,
+ let window_0 = Window {
+ panes: pane_grid::State::new(Pane::new(
+ 0,
+ pane_grid::Axis::Horizontal,
+ ))
+ .0,
focus: None,
- title: String::from("Default window"),
+ title: String::from("Window 1"),
+ };
+ let window_1 = Window {
+ panes: pane_grid::State::new(Pane::new(
+ 1,
+ pane_grid::Axis::Horizontal,
+ ))
+ .0,
+ focus: None,
+ title: String::from("Window 2"),
};
(
Example {
- windows: HashMap::from([(window::Id::new(0usize), window)]),
- panes_created: 1,
+ windows: HashMap::from([
+ (window::Id::new(0usize), window_0),
+ (window::Id::new(1usize), window_1),
+ ]),
+ panes_created: 2,
_focused: window::Id::new(0usize),
},
Command::none(), |
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
/// TODO(derezzedex) | ||
pub struct Id(u64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hashing an arbitrary hashable as a u64
, it might be better to define this more like iced_native::widget::Id
? Which is either a usize
that is made unique by auto-incrementing, or a string.
Generating unique IDs with an incrementing integer makes sense for dynamic spawning of windows, where IDs can be stored in the model. Should be more collision resistant than hashes.
This PR roughly implements multi-window support, as described in the RFC: iced-rs/rfcs#8.
The
multi_window
example showcases a multi-window version of thepane_grid
example.Note: This is still work-in-progress, and will remain a draft while the RFC hasn't been merged.