diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-25 17:15:04 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-25 17:16:05 +0200 |
commit | 1887dc6de49d5cfba48ed73be346f158f023ff21 (patch) | |
tree | d8a7ccf96856b12a4a707352ec5e36e70cd42eb2 /Libraries/LibGUI/ToolBarContainer.cpp | |
parent | 9c772a64a1bcbc088208183d8fcb0b8a03b8b708 (diff) | |
download | serenity-1887dc6de49d5cfba48ed73be346f158f023ff21.zip |
LibGUI: Make ToolBarContainer better at reacting to child events
Now you can remove a ToolBar from a ToolBarContainer and it will update
its own preferred size automatically.
Diffstat (limited to 'Libraries/LibGUI/ToolBarContainer.cpp')
-rw-r--r-- | Libraries/LibGUI/ToolBarContainer.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Libraries/LibGUI/ToolBarContainer.cpp b/Libraries/LibGUI/ToolBarContainer.cpp index 6d7bc8507c..4a453cacbe 100644 --- a/Libraries/LibGUI/ToolBarContainer.cpp +++ b/Libraries/LibGUI/ToolBarContainer.cpp @@ -32,9 +32,34 @@ namespace GUI { +void ToolBarContainer::child_event(Core::ChildEvent& event) +{ + Frame::child_event(event); + + if (event.type() == Core::Event::ChildAdded) { + if (event.child() && event.child()->is_widget()) + did_add_toolbar((Widget&)*event.child()); + } else if (event.type() == Core::Event::ChildRemoved) { + if (event.child() && event.child()->is_widget()) { + did_remove_toolbar((Widget&)*event.child()); + } + } +} + +void ToolBarContainer::did_remove_toolbar(Widget& toolbar) +{ + m_toolbars.remove_first_matching([&](auto& entry) { return entry.ptr() == &toolbar; }); + recompute_preferred_size(); +} + void ToolBarContainer::did_add_toolbar(Widget& toolbar) { m_toolbars.append(toolbar); + recompute_preferred_size(); +} + +void ToolBarContainer::recompute_preferred_size() +{ int preferred_size = 4 + (m_toolbars.size() - 1) * 2; for (auto& toolbar : m_toolbars) { |