Skip to content

Consistent Widget::diff logic#3348

Merged
hecrj merged 9 commits into
masterfrom
widget-settling
Jun 4, 2026
Merged

Consistent Widget::diff logic#3348
hecrj merged 9 commits into
masterfrom
widget-settling

Conversation

@hecrj
Copy link
Copy Markdown
Member

@hecrj hecrj commented Jun 3, 2026

This PR changes the Widget trait to call diff logic consistently after every view with a mutable self.

Effectively, this makes the diff method 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 diff method. This allows dynamic widgets like component (and the upcoming transition in #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 Shrink and the default "inherited sizing" strategy of containers. This prompted the introduction of a new Length variant called Fit.

Using Fit should be a no-op in most cases, since it's the default sizing strategy of most widgets. However, Fit will become quite useful soon.

Furthermore, since diff is now called after every view, the children method in Widget becomes redundant. We can simply initialize Tree::children as an empty Vec and let diff do the rest–removing the need to keep both children and diff logic synchronized.

Finally, since sizing inheritance can be properly done during diff, we can also get rid of the size_hint hack.

Lots of things clicking into place here!

@hecrj hecrj added this to the 0.15 milestone Jun 3, 2026
@hecrj hecrj added improvement An internal improvement widget layout change labels Jun 3, 2026
It allows re-triggering `Widget::diff` logic from `update`
@hecrj hecrj merged commit 15c231f into master Jun 4, 2026
30 checks passed
@hecrj hecrj deleted the widget-settling branch June 4, 2026 04:40
@hecrj hecrj mentioned this pull request Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant