[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::ApplicationtraitThe 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::Applicationtrait for their applications if they want the capability of having more than one window.This new trait adds a
window::Idparameter to several methods of the familiarApplicationtrait, e.g.Here a user can choose which
Elementto return for each window, based on itswindow::Id. Awindow::Idis 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::MAINto represent the first window spawned.👐 Creating a window
Users can create a new window with the
window::spawncommand, which takes awindow::Idandwindow::Settings.🌂 Closing a window
A user can close a specific window with the
window::close(id)command. I've utilized the existingexit_on_close_requestfield oficed::Settingsto 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_requestdoesn'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::Createdwhich is emitted after the window is finished being created by winit, orwindow::Event::Destroyedwhich is emitted after the window is fully destroyed. There is alsowindow::Event::CloseRequested, which can be subscribed to to close the window with thewindow::closecommand.🚤 Known areas to improve performance:
Rendererper-window, each with their ownBackend. This is very bad! We should be sharing a singleBackendacross multipleRenderers. This will take some refactoring to ourCompositorand ourBackendto 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:
Programwithout amulti_window::Applicationtrait. Not sure if we even want this behavior though.Tested on latest MacOS, PopOS & Windows 10.