summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibGUI/ToolBarContainer.cpp25
-rw-r--r--Libraries/LibGUI/ToolBarContainer.h10
2 files changed, 28 insertions, 7 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) {
diff --git a/Libraries/LibGUI/ToolBarContainer.h b/Libraries/LibGUI/ToolBarContainer.h
index 4dcbf93676..40ffddc4eb 100644
--- a/Libraries/LibGUI/ToolBarContainer.h
+++ b/Libraries/LibGUI/ToolBarContainer.h
@@ -35,20 +35,16 @@ class ToolBarContainer : public Frame {
C_OBJECT(ToolBarContainer);
public:
- template<class T, class... Args>
- inline T& add(Args&&... args)
- {
- auto& child = Frame::add<T>(forward<Args>(args)...);
- did_add_toolbar(child);
- return child;
- }
private:
explicit ToolBarContainer(Gfx::Orientation = Gfx::Orientation::Horizontal);
virtual void paint_event(GUI::PaintEvent&) override;
+ virtual void child_event(Core::ChildEvent&) override;
void did_add_toolbar(Widget&);
+ void did_remove_toolbar(Widget&);
+ void recompute_preferred_size();
Gfx::Orientation m_orientation { Gfx::Orientation::Horizontal };