summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-08 21:18:46 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-09 00:41:00 +0100
commitd22d9874f7e50cfd9b085765bc83b8032bade7cc (patch)
treee59d58785488af0883691421e7566d296b31c004
parent0d2495e4e772e3e6a7d24b53bf8e958e35c956a1 (diff)
downloadserenity-d22d9874f7e50cfd9b085765bc83b8032bade7cc.zip
LibGUI: Allow overriding the button size when constructing GToolBar
This makes it easy to create a toolbar housing buttons of a size other than 16x16.
-rw-r--r--Libraries/LibGUI/GToolBar.cpp11
-rw-r--r--Libraries/LibGUI/GToolBar.h3
2 files changed, 8 insertions, 6 deletions
diff --git a/Libraries/LibGUI/GToolBar.cpp b/Libraries/LibGUI/GToolBar.cpp
index 058d5a2c66..6e21ddbd1d 100644
--- a/Libraries/LibGUI/GToolBar.cpp
+++ b/Libraries/LibGUI/GToolBar.cpp
@@ -5,19 +5,20 @@
#include <LibGUI/GToolBar.h>
GToolBar::GToolBar(GWidget* parent)
- : GToolBar(Orientation::Horizontal, parent)
+ : GToolBar(Orientation::Horizontal, 16, parent)
{
}
-GToolBar::GToolBar(Orientation orientation, GWidget* parent)
+GToolBar::GToolBar(Orientation orientation, int button_size, GWidget* parent)
: GWidget(parent)
+ , m_button_size(button_size)
{
if (orientation == Orientation::Horizontal) {
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
- set_preferred_size(0, 28);
+ set_preferred_size(0, button_size + 12);
} else {
set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
- set_preferred_size(28, 0);
+ set_preferred_size(button_size + 12, 0);
}
set_layout(make<GBoxLayout>(orientation));
layout()->set_spacing(0);
@@ -46,7 +47,7 @@ void GToolBar::add_action(GAction& action)
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed);
ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed);
- button->set_preferred_size(24, 24);
+ button->set_preferred_size(m_button_size + 8, m_button_size + 8);
m_items.append(move(item));
}
diff --git a/Libraries/LibGUI/GToolBar.h b/Libraries/LibGUI/GToolBar.h
index 6719fcc787..bc7145ed91 100644
--- a/Libraries/LibGUI/GToolBar.h
+++ b/Libraries/LibGUI/GToolBar.h
@@ -18,7 +18,7 @@ public:
protected:
explicit GToolBar(GWidget* parent);
- explicit GToolBar(Orientation, GWidget* parent);
+ explicit GToolBar(Orientation, int button_size, GWidget* parent);
virtual void paint_event(GPaintEvent&) override;
@@ -33,5 +33,6 @@ private:
RefPtr<GAction> action;
};
NonnullOwnPtrVector<Item> m_items;
+ int m_button_size { 16 };
bool m_has_frame { true };
};