Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have been using iced for my projects for a year now. My concern is that the Application::view function is mutable. I don't know, maybe you have your own solution, but I decided to offer my own. I know that you don't like to go to the code without a preliminary discussion, but my English is bad.
This is my first PR not only in this project, but also my first contribution to open source in general. So do not judge strictly.
This PR allows you to get rid of the changeable Application function::view, by storing states in a special WidgetStateStorage struct. This storage is formed during the deletion of the current Element tree and before creating a new Element tree, during the Application::view call. StateStorage is temporarily stored in the Cache and is used inside the UserInterface::builder.
Since widgets themselves store their state, now there is no longer a need to store widget states inside the Application, and therefore there is no need inside the Application::view function to pass a mutable reference to the state.
But what if you need to change the state of some widget inside the Application::update function? Then it is possible to use a mutable reference to StateStorage, which is passed to the argument of the update function.
Each State has its own ID, which is manually specified or automatically generated. To get a mutable reference to the state of a specific widget inside the Application::update function, you must assign an ID to this widget in advance.
A tree of elements of great depth is sometimes divided into several "components", and in this case, an ID conflict may occur. To avoid this, a multi-level ID in the form of PathBuf is used.
Two functions have been added for the widget function. "into_states" - the widget is deleted and returns its state, "apply_status" - the widget finds and assigns its state.