From d8320d0a1498d0f6cd59db171821042e1ea04a32 Mon Sep 17 00:00:00 2001 From: Torstennator Date: Fri, 14 Jul 2023 18:34:06 +0200 Subject: [PATCH] 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. --- Userland/Services/WindowServer/Menu.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index 0dd8343b60..629bc0ba64 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -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;