summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Toolbar.cpp
diff options
context:
space:
mode:
authorFrHun <28605587+frhun@users.noreply.github.com>2022-10-05 18:19:18 +0200
committerSam Atkins <atkinssj@gmail.com>2022-10-06 12:17:38 +0100
commiteefe6e35ac06f1909a0ec5c1a739f34aef68c538 (patch)
treef82faded5df41ed651929e7826d0aaa31dabd137 /Userland/Libraries/LibGUI/Toolbar.cpp
parent41744a4a870612028ef15a91dc8988355ad82d08 (diff)
downloadserenity-eefe6e35ac06f1909a0ec5c1a739f34aef68c538.zip
LibGUI: Add option to move Toolbar items to overflow menu in groups
When items are sent to the overflow menu one by one, it can happen that buttons that are heavily related, and don't make sense without one another (either visually or logically) are separated. This new option enables the developer to choose the "grouping" behavior, of sending all items that are not separated to the overflow menu together, as soon as one of them doesn't have enough space to be displayed. (provided the toolbar is set as collapsible)
Diffstat (limited to 'Userland/Libraries/LibGUI/Toolbar.cpp')
-rw-r--r--Userland/Libraries/LibGUI/Toolbar.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp
index 5380af356a..daca0bd235 100644
--- a/Userland/Libraries/LibGUI/Toolbar.cpp
+++ b/Userland/Libraries/LibGUI/Toolbar.cpp
@@ -27,6 +27,7 @@ Toolbar::Toolbar(Orientation orientation, int button_size)
, m_button_size(button_size)
{
REGISTER_BOOL_PROPERTY("collapsible", is_collapsible, set_collapsible);
+ REGISTER_BOOL_PROPERTY("grouped", is_grouped, set_grouped);
if (m_orientation == Orientation::Horizontal)
set_fixed_height(button_size);
@@ -202,6 +203,16 @@ ErrorOr<void> Toolbar::update_overflow_menu()
return {};
}
+ if (m_grouped) {
+ for (size_t i = marginal_index.value(); i > 0; --i) {
+ auto& item = m_items.at(i);
+ if (item.type == Item::Type::Separator)
+ break;
+ item.widget->set_visible(false);
+ marginal_index = i;
+ }
+ }
+
if (!m_overflow_action)
TRY(create_overflow_objects());
m_overflow_action->set_enabled(true);