1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

WindowServer: Fix menu height when invisible items are involved

This patch checks for visible items to determine the menu height. Now
the last visible item is used to determine the height of the menu.
Before this patch that menu height could be wrong e.g. if the last item
was not visible.
This commit is contained in:
Torstennator 2023-07-14 18:34:06 +02:00 committed by Jelle Raaijmakers
parent 8c681a1603
commit d8320d0a14

View file

@ -129,7 +129,14 @@ Window& Menu::ensure_menu_window(Gfx::IntPoint position)
auto calculate_window_rect = [&]() -> Gfx::IntRect {
int window_height_available = screen.height() - frame_thickness() * 2;
int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2;
int content_height = m_items.is_empty() ? 0 : m_items.last()->rect().bottom() + frame_thickness();
int content_height = 0;
// find the last visible item to determine the required menu height
for (size_t i = m_items.size(); i > 0; i--) {
if (m_items[i - 1]->is_visible()) {
content_height = m_items[i - 1]->rect().bottom() + frame_thickness();
break;
}
}
int window_height = min(max_window_height, content_height);
if (window_height < content_height) {
m_scrollable = true;