Skip to content

Commit

Permalink
LibGUI: Add existing children widgets when layout manager changed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mhjacobson authored and awesomekling committed Jan 12, 2022
1 parent 34c5d33 commit 037fbbf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Userland/Libraries/LibGUI/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 037fbbf

Please sign in to comment.