summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vella <nick@nxk.io>2021-02-17 00:48:14 +1100
committerAndreas Kling <kling@serenityos.org>2021-02-17 23:06:19 +0100
commit05914d2e9a81243a82369862e28c8ae59d6a38cd (patch)
tree30f6c65eb4ec7a46b5aed32e72d0fc6418675a26
parent2d1cfa7d1142bace04a13d57db6e3f16c79f1e39 (diff)
downloadserenity-05914d2e9a81243a82369862e28c8ae59d6a38cd.zip
LibGUI: Correctly handle ComboBox list windows of less than three items (~50px) in height.
By default, a Window has a minimum size of 50x50 - ComboBox lists aren't always this tall. We now set the minimum height of the ComboBox Window according to the height of three items, or the total height of all the items in the list, whichever is smaller. This means there is no longer any unpainted space in the list window due to the shortfall between the ListBox widget and Window heights, and the ComboBox list window always remains a comfortable height for viewing. :^)
-rw-r--r--Userland/Libraries/LibGUI/ComboBox.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/ComboBox.cpp b/Userland/Libraries/LibGUI/ComboBox.cpp
index 73721a4357..510074df8c 100644
--- a/Userland/Libraries/LibGUI/ComboBox.cpp
+++ b/Userland/Libraries/LibGUI/ComboBox.cpp
@@ -244,6 +244,13 @@ void ComboBox::open()
// change the list view's selected item without triggering a change to it.
m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set);
}
+
+ // Set the minimum minimum height of the list window to the height of three
+ // items or the row count, whichever is smaller, plus the frame thickness.
+ // This prevents the list from becoming infinitesimally small when pushed
+ // up against the screen edge.
+ m_list_window->set_minimum_size(1, min(3, model()->row_count()) * m_list_view->item_height() + m_list_view->frame_thickness() * 2);
+
m_list_window->set_rect(list_window_rect);
m_list_window->show();
}