From 037fbbf5d94360ee7f8b54efa222621ac670db10 Mon Sep 17 00:00:00 2001 From: Matt Jacobson Date: Tue, 11 Jan 2022 21:32:29 -0500 Subject: [PATCH] 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. --- Userland/Libraries/LibGUI/Layout.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibGUI/Layout.cpp b/Userland/Libraries/LibGUI/Layout.cpp index 8ee264a046..76818bbb63 100644 --- a/Userland/Libraries/LibGUI/Layout.cpp +++ b/Userland/Libraries/LibGUI/Layout.cpp @@ -46,12 +46,17 @@ void Layout::notify_adopted(Badge, 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) { VERIFY(m_owner == &widget); m_owner.clear(); + m_entries.clear(); } ErrorOr Layout::try_add_entry(Entry&& entry)