1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

LibGUI: ComboBox now goes upwards when running out of room to render

This commit is contained in:
Matthew Jones 2021-06-02 18:15:50 -06:00 committed by Andreas Kling
parent 36a1162eb8
commit ef92493aba

View file

@ -235,11 +235,15 @@ void ComboBox::open()
m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set); 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 // Change direction and go upwards to prevent the list from becoming
// items or the row count, whichever is smaller, plus the frame thickness. // infinitesimally small when pushed up against the screen edge.
// This prevents the list from becoming infinitesimally small when pushed auto minimum_height = min(3, model()->row_count()) * m_list_view->item_height() + m_list_view->frame_thickness() * 2;
// up against the screen edge. bool go_upwards_instead = list_window_rect.height() <= minimum_height;
m_list_window->set_minimum_size(1, min(3, model()->row_count()) * m_list_view->item_height() + m_list_view->frame_thickness() * 2); if (go_upwards_instead) {
auto origin_point = my_screen_rect.top_left();
list_window_rect = { Gfx::IntPoint { origin_point.x(), origin_point.y() - size.height() }, size };
list_window_rect.intersect(Desktop::the().rect());
}
m_list_window->set_rect(list_window_rect); m_list_window->set_rect(list_window_rect);
m_list_window->show(); m_list_window->show();