1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:37:43 +00:00

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)
This commit is contained in:
FrHun 2022-10-05 18:19:18 +02:00 committed by Sam Atkins
parent 41744a4a87
commit eefe6e35ac
2 changed files with 14 additions and 0 deletions

View file

@ -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);