Discussion about this post

User's avatar
Jordan's avatar

Correct me if I'm wrong, but the order in which we calculate parent-dependent sizes vs child-dependent sizes doesn't matter right? In other words, we could calculate all widgets with UI_SizeKind_ChildrenSum first, then calculate all widgets with UI_SizeKind_ParentPercent after. This means we could do both child- and parent-dependent in a single tree traversal: child-dependent on the way down then parent-dependent on the way back up. Since presumabely you'd have the node stack at the bottom of the downwards descent?

Expand full comment
Bryan Lee's avatar

On the subject of deriving the key for caching immediate mode widgets to their retained state, I feel like I should mention how React solved the problem with its hooks model.

React caches retained values per invocation (what they call a hook) rather than per widget, and requires that each widget calls each hook in a deterministic order (hooks cannot be called conditionally in a widget's body). The key for each retained value then is simply its called position in the widget hierarchy.

This allows primitives to be composed together into higher-level utilities surprisingly well, as the calling order of retained values remains constant even if extracted into utility functions.

React keeps track of which hooks are called whenever a widget is mounted, and simply removes them from the calling order when the widget is unmounted, effectively updating the key for retained values for widgets later in the traversal, and thereby enabling conditional rendering.

Expand full comment
11 more comments...

No posts