1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:57:45 +00:00

LibGUI: Add existing children widgets when layout manager changed

If a widget gains a layout manager after it already has child widgets,
the existing widgets are unknown to the layout.  Additionally, if a
layout is reused, it may end up managing children of multiple different
widgets.

To simplify this, clear the entries of a layout manager when its owner
changes, and add any existing children when a new owner comes along.
This commit is contained in:
Matt Jacobson 2022-01-11 21:32:29 -05:00 committed by Andreas Kling
parent 34c5d33eb0
commit 037fbbf5d9

View file

@ -46,12 +46,17 @@ void Layout::notify_adopted(Badge<Widget>, Widget& widget)
if (m_owner == &widget)
return;
m_owner = widget;
m_owner->for_each_child_widget([&](Widget& child) {
add_widget(child);
return IterationDecision::Continue;
});
}
void Layout::notify_disowned(Badge<Widget>, Widget& widget)
{
VERIFY(m_owner == &widget);
m_owner.clear();
m_entries.clear();
}
ErrorOr<void> Layout::try_add_entry(Entry&& entry)