-
-
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
[Feature] 🪟 Multi Window 🪟 .. redux! #1964
Conversation
Instead of creating a separate `multi_window::Program`, the new `multi_window::Application` unifies both traits
events internaly
32dcf5f
to
5c5e765
Compare
Alright! Finally got this to the finish line! Great stuff, @derezzedex and @bungoboingo! 🥳 I have refactored a bunch of stuff here and there. Most important changes are:
And I think that's it! I have most definitely changed some of the behavior (i.e. Let me know what you think! And let's ship this! 🚢 |
LGTM, let's 🚢 it!!! |
Will all windows redraw on state change? I think this is one thing i dislike and which i think can be improved. I hoped for selective window redraw. |
Currently all windows are being redrawn due to existing limitations; there are plans in the near-ish future to have widgets explicitly request to be redrawn on state changes, which will fix this behavior. Lots of iterations will be made for multi-window performance increases, like shared rendering resources, etc. They will all be added in time! |
This PR introduces support for multiple windows!
Branched off of @derezzedex's old PR (closes #1439), which implements RFC #8.
Note that much of the code in this PR is from his branch, updated to Iced master from 0.4, with some added bits on top and small tweaks/changes.
multi_window.mov
Summary 🪟
🆕 A new
multi_window::Application
traitThe goal is to be as non-invasive as possible when adding support for multiple windows for existing Iced users. Users can now implement the
multi_window::Application
trait for their applications if they want the capability of having more than one window.This new trait adds a
window::Id
parameter to several methods of the familiarApplication
trait, e.g.Here a user can choose which
Element
to return for each window, based on itswindow::Id
. Awindow::Id
is a unique identifier for a window, created when the window is first spawned. Users can store this ID and use it to reference specific windows. This is different from winit'sWindowId
. Internally, we reservewindow::Id::MAIN
to represent the first window spawned.👐 Creating a window
Users can create a new window with the
window::spawn
command, which takes awindow::Id
andwindow::Settings
.🌂 Closing a window
A user can close a specific window with the
window::close(id)
command. I've utilized the existingexit_on_close_request
field oficed::Settings
to determine whether or not to close the entire application when the "main" or first window is closed. Not sure if this is wanted or needed behavior, but thisexit_on_close_request
doesn't make much sense in multi window otherwise. Could do a different set of settings, or just ignore it!🤔 New Window Events
Users can choose to listen to new window events implemented for multi window, such as
window::Event::Created
which is emitted after the window is finished being created by winit, orwindow::Event::Destroyed
which is emitted after the window is fully destroyed. There is alsowindow::Event::CloseRequested
, which can be subscribed to to close the window with thewindow::close
command.🚤 Known areas to improve performance:
Renderer
per-window, each with their ownBackend
. This is very bad! We should be sharing a singleBackend
across multipleRenderer
s. This will take some refactoring to ourCompositor
and ourBackend
to make sure that all the caching is refactored with multiple surfaces in mind.multi_window::Application::update
. This requires us to rebuild all user interfaces when processing any message, regardless of if that message affects all windows or just oneOther suggestions very welcome and appreciated!
👻 Commit history..
Yes it's a mess. I tried to rebase from the original PR, but that was done before the great Purification which changed nearly all of the codebase, and it was a real struggle. If we care enough I will get back in the trenches and try to sort out the commit history, but for now it's a bit of a frankenstein.
TODOs:
Program
without amulti_window::Application
trait. Not sure if we even want this behavior though.Tested on latest MacOS, PopOS & Windows 10.