mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
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.
This commit is contained in:
parent
6330de15b6
commit
b868337d5e
Notes:
sideshowbarker
2024-07-17 06:20:06 +09:00
Author: https://github.com/frhun Commit: https://github.com/SerenityOS/serenity/commit/b868337d5e Pull-request: https://github.com/SerenityOS/serenity/pull/15484 Reviewed-by: https://github.com/AtkinsSJ ✅
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user