summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authormartinfalisse <martinmotteditfalisse@gmail.com>2022-01-03 10:52:38 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-03 15:49:07 +0100
commit452150c632c1f2ee63839ae7597eb7e511cde6e9 (patch)
tree7b126ba5c86e281978f0b8122e363df7d0d76485 /Userland/Libraries
parente824a2da90d2a3767cb6ce1ba2138a35f38103ab (diff)
downloadserenity-452150c632c1f2ee63839ae7597eb7e511cde6e9.zip
LibGUI: Bring entire cell into view after auto scroll into view
On account of row and column headers, when a user navigates to a cell (for example in the spreadsheet application) that is outside of the view, the cell is not properly aligned and so is partially cut-off. This fix takes into account the row and column headers when calculating the Rect to pass to the scroll_into_view function.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/AbstractTableView.cpp13
-rw-r--r--Userland/Libraries/LibGUI/AbstractTableView.h1
2 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractTableView.cpp b/Userland/Libraries/LibGUI/AbstractTableView.cpp
index 52d92f4632..ac872fda81 100644
--- a/Userland/Libraries/LibGUI/AbstractTableView.cpp
+++ b/Userland/Libraries/LibGUI/AbstractTableView.cpp
@@ -276,7 +276,7 @@ void AbstractTableView::scroll_into_view(const ModelIndex& index, bool scroll_ho
Gfx::IntRect rect;
switch (selection_behavior()) {
case SelectionBehavior::SelectItems:
- rect = content_rect(index);
+ rect = cell_rect(index.row(), index.column());
break;
case SelectionBehavior::SelectRows:
rect = row_rect(index.row());
@@ -324,6 +324,17 @@ 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 916ecf05c2..612c4b5625 100644
--- a/Userland/Libraries/LibGUI/AbstractTableView.h
+++ b/Userland/Libraries/LibGUI/AbstractTableView.h
@@ -51,6 +51,7 @@ 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;