diff options
author | FrHun <28605587+frhun@users.noreply.github.com> | 2022-10-05 22:17:38 +0200 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-10-06 12:17:38 +0100 |
commit | b868337d5eec0ccc30ac4dcdcf441cc0115de245 (patch) | |
tree | 0d225389bd6826247e8a316b673360532a185cf8 /Userland/Libraries/LibGUI/Toolbar.cpp | |
parent | 6330de15b62d30bbd7a17d714d40d08b97afdd86 (diff) | |
download | serenity-b868337d5eec0ccc30ac4dcdcf441cc0115de245.zip |
LibGUI: Include overflow button in overflow calculation only when shown
This prevents items from being put in the overflow menu, even though
there is still enough space for all items to be shown, because the
overflow button does not take up space when it is not needed.
Diffstat (limited to 'Userland/Libraries/LibGUI/Toolbar.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/Toolbar.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/Toolbar.cpp b/Userland/Libraries/LibGUI/Toolbar.cpp index daca0bd235..3e0801d9c0 100644 --- a/Userland/Libraries/LibGUI/Toolbar.cpp +++ b/Userland/Libraries/LibGUI/Toolbar.cpp @@ -181,13 +181,13 @@ ErrorOr<void> Toolbar::update_overflow_menu() Optional<size_t> marginal_index {}; auto position { 0 }; auto is_horizontal { m_orientation == Gfx::Orientation::Horizontal }; - auto margin { is_horizontal ? layout()->margins().right() : layout()->margins().bottom() }; + auto margin { is_horizontal ? layout()->margins().horizontal_total() : layout()->margins().vertical_total() }; auto toolbar_size { is_horizontal ? width() : height() }; for (size_t i = 0; i < m_items.size() - 1; ++i) { auto& item = m_items.at(i); auto item_size = is_horizontal ? item.widget->width() : item.widget->height(); - if (position + item_size + m_button_size + margin > toolbar_size) { + if (position + item_size + margin > toolbar_size) { marginal_index = i; break; } @@ -203,6 +203,18 @@ ErrorOr<void> Toolbar::update_overflow_menu() return {}; } + if (marginal_index.value() > 0) { + for (size_t i = marginal_index.value() - 1; i > 0; --i) { + auto& item = m_items.at(i); + auto item_size = is_horizontal ? item.widget->width() : item.widget->height(); + if (position + m_button_size + margin <= toolbar_size) + break; + item.widget->set_visible(false); + position -= item_size; + marginal_index = i; + } + } + if (m_grouped) { for (size_t i = marginal_index.value(); i > 0; --i) { auto& item = m_items.at(i); |