From 1097f3066e8fd6b029dbab024491cdf3fc2d2236 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Sun, 2 Apr 2023 13:26:35 -0400 Subject: [PATCH] LibGUI: Open and increment ComboBox ListViews by exact steps This feels a bit nicer and always places the current index at the top of visible content in long scrollable lists. --- Userland/Libraries/LibGUI/ComboBox.cpp | 7 +++++-- Userland/Libraries/LibGUI/ListView.cpp | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/ComboBox.cpp b/Userland/Libraries/LibGUI/ComboBox.cpp index 0c7f3cd117..fc80fd1fc8 100644 --- a/Userland/Libraries/LibGUI/ComboBox.cpp +++ b/Userland/Libraries/LibGUI/ComboBox.cpp @@ -271,8 +271,11 @@ void ComboBox::open() m_list_window->set_rect(rect); m_list_view->set_min_size(rect.size()); - if (m_selected_index.has_value()) - m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set); + if (m_selected_index.has_value()) { + m_list_view->set_cursor(m_selected_index.value(), AbstractView::SelectionUpdate::Set, false); + auto index_top = m_list_view->vertical_scrollbar().step() * m_selected_index.value().row(); + m_list_view->vertical_scrollbar().set_value(index_top); + } m_list_window->show(); } diff --git a/Userland/Libraries/LibGUI/ListView.cpp b/Userland/Libraries/LibGUI/ListView.cpp index f89509043e..c584e93b48 100644 --- a/Userland/Libraries/LibGUI/ListView.cpp +++ b/Userland/Libraries/LibGUI/ListView.cpp @@ -21,6 +21,7 @@ ListView::ListView() set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); set_searchable(true); + vertical_scrollbar().set_step(item_height()); } ListView::~ListView() = default;