Consistent Widget::diff logic#3348
Merged
Merged
Conversation
It allows re-triggering `Widget::diff` logic from `update`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR changes the
Widgettrait to calldifflogic consistently after everyviewwith a mutableself.Effectively, this makes the
diffmethod a lot more powerful; since it can now be used to run initialization logic in a consistent way.For instance, sizing inheritance has been moved from widget tree construction to the
diffmethod. This allows dynamic widgets likecomponent(and the upcomingtransitionin #3344) to properly report their final size, since they now have a chance to access persistent state.However, given that now sizing inheritance is done after widget construction, we need a way to differentiate between
Shrinkand the default "inherited sizing" strategy of containers. This prompted the introduction of a newLengthvariant calledFit.Using
Fitshould be a no-op in most cases, since it's the default sizing strategy of most widgets. However,Fitwill become quite useful soon.Furthermore, since
diffis now called after everyview, thechildrenmethod inWidgetbecomes redundant. We can simply initializeTree::childrenas an emptyVecand letdiffdo the rest–removing the need to keep bothchildrenanddifflogic synchronized.Finally, since sizing inheritance can be properly done during
diff, we can also get rid of thesize_hinthack.Lots of things clicking into place here!