From 8eb8949d9cb8c574ca58dad69337545247895766 Mon Sep 17 00:00:00 2001 From: martinfalisse Date: Wed, 5 Jan 2022 21:14:08 +0100 Subject: [PATCH] LibGUI: Calculate row position for scroll into view When a user is navigating a table view with arrow keys and a row is outside of the current view, then scroll_into_view is called, and the position of the rectangle passed to this should take into account the column headers. This can be seen making more pleasant the navigation in the System Monitor in the Processes view, for example. --- Userland/Libraries/LibGUI/AbstractTableView.cpp | 17 +++++------------ Userland/Libraries/LibGUI/AbstractTableView.h | 1 - 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibGUI/AbstractTableView.cpp b/Userland/Libraries/LibGUI/AbstractTableView.cpp index ac872fda81..b99661220c 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.cpp +++ b/Userland/Libraries/LibGUI/AbstractTableView.cpp @@ -276,12 +276,16 @@ void AbstractTableView::scroll_into_view(const ModelIndex& index, bool scroll_ho Gfx::IntRect rect; switch (selection_behavior()) { case SelectionBehavior::SelectItems: - rect = cell_rect(index.row(), index.column()); + rect = content_rect(index); + if (row_header().is_visible()) + rect.set_left(rect.left() - row_header().width()); break; case SelectionBehavior::SelectRows: rect = row_rect(index.row()); break; } + if (column_header().is_visible()) + rect.set_top(rect.top() - column_header().height()); AbstractScrollableWidget::scroll_into_view(rect, scroll_horizontally, scroll_vertically); } @@ -324,17 +328,6 @@ Gfx::IntRect AbstractTableView::content_rect(const ModelIndex& index) const return content_rect(index.row(), index.column()); } -Gfx::IntRect AbstractTableView::cell_rect(int row, int column) const -{ - auto cell_rect = this->content_rect(row, column); - if (row_header().is_visible()) - cell_rect.set_left(cell_rect.left() - row_header().width()); - if (column_header().is_visible()) - cell_rect.set_top(cell_rect.top() - column_header().height()); - - return cell_rect; -} - Gfx::IntRect AbstractTableView::row_rect(int item_index) const { return { row_header().is_visible() ? row_header().width() : 0, diff --git a/Userland/Libraries/LibGUI/AbstractTableView.h b/Userland/Libraries/LibGUI/AbstractTableView.h index 612c4b5625..916ecf05c2 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.h +++ b/Userland/Libraries/LibGUI/AbstractTableView.h @@ -51,7 +51,6 @@ public: virtual Gfx::IntRect content_rect(const ModelIndex&) const override; Gfx::IntRect content_rect(int row, int column) const; - Gfx::IntRect cell_rect(int row, int column) const; Gfx::IntRect row_rect(int item_index) const; virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const override;