Repository navigation
feat(widget): runtime child mutation on containers (#243) - #252
Merged
Merged
Conversation
Make WidgetBase the single owner of a container's membership child list. Mutators now set the real parent (via SetSelf), mount a child when the container is mounted, unmount on removal (releasing bindings and clearing the cached scene), release keyboard focus inside a removed subtree, and mark layout dirty. RemoveChild preserves order instead of swap-removing; MoveChild relinks without detaching. MountTree/UnmountTree store and clear the mount context so runtime attach can mount. Refs #243
…tore Box and overlay.Container drop their shadow child fields and the Children overrides; Box iterates a Children() snapshot per pass so a child removed during layout, draw or event dispatch cannot shift the slice or skip a sibling. Both constructors call SetSelf so AddChild links the parent. Refs #243
A widget that captured the pointer (ADR-031) or last received hover and is then removed from the tree must stop receiving events. Clear the window's stale references before dispatch when the widget is no longer mounted, so a detached subtree is neither pinned in memory nor delivered to. Refs #243
kolkov
force-pushed
the
fix/243-runtime-content-mutation
branch
from
November 8, 2026 14:30
bfa7d4a to
846c912
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Part of #243, the container side. The dropdown side is #251.
Today
BoxWidgetkeeps its ownchildrenslice, so theAddChild/RemoveChild/InsertChild/ClearChildrenit gets fromWidgetBasechange a list the box never reads (#243, discussion #501).RemoveChildalso swap-removes, which reorders the remaining children, and no mutator ever links a parent or touches the lifecycle.The change follows Flutter (
MultiChildRenderObjectElement.updateChildren,adoptChild/dropChild,FocusAttachment.detach), Qt6 (QLayout::removeWidget+ deferredLayoutRequest) and GTK4 (gtk_widget_unparent): a child-list mutation is one operation that covers membership, the parent link, attach/detach, layout invalidation and focus. What it does:WidgetBaseowns the children;BoxWidgetandoverlay.Containerdrop their shadow lists and route through it.MoveChild(from, to)reorders without detaching, so the moved child keeps its state and bindings.AddChild/InsertChildset the real parent and mount the subtree with the container's stored context when the container is mounted;RemoveChild/RemoveChildAt/ClearChildrenunmount (bindings released, cached scene dropped, parent cleared).RemoveChildpreserves order now.FocusedWidgetnever reports a widget that left the tree, not even until the next frame).capturedWidget/hoveredWidgetonce that widget is no longer mounted, before the next event is dispatched (ADR-031).MarkNeedsLayout()and nothing else; paint follows the layout-cache-miss path, so mutation inside a repaint boundary does not dirty its ancestors (ADR-024/028/032).New public API on
WidgetBase:SetSelfandMoveChild.SetSelfis framework plumbing, not application API: it is exported only because a container in another package embedsWidgetBaseand registers itself from its own constructor (the doc comment says so). The mount context is an unexported setter thatMountTreereaches through a type assertion, so it adds no public surface. Behaviour changes, all in the issue:AddChildsets the parent,RemoveChildkeeps order, removed children are unmounted.Tests are written first and fail on the old code (failure table in the card): 15 of the 17 items from the reference research, including mutation during draw, focus release, capture release, mount-on-add for a mounted box, reorder identity, and repaint-boundary isolation. The other two: item 10 (binding survives a reorder) is replaced by a lighter identity test, since
MoveChildnever detaches; item 16 (dropdown items signal) is not this PR — it shipped in #251 with its own tests.Deliberately not here: cancelling a removed widget's gesture recognizers. An arena prune keyed on "recognizer no longer tracks the pointer" would be dead code until widgets cancel their gestures on unmount, so it is carded separately (P1-EVENT-001) instead of shipped unwired.
Gates on the rebased branch with
GOWORK=off: build, vet, the full suite (62 packages) and golangci-lint (0 issues, nolevel=error). Visual pass (add/remove at runtime in hello/gallery) is for the release smoke, by the user.