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. :^)
This commit is contained in:
Nick Vella 2021-02-17 00:48:14 +11:00 committed by Andreas Kling
parent 2d1cfa7d11
commit 05914d2e9a
Notes: sideshowbarker 2024-07-18 22:11:00 +09:00

View file

@ -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();
}