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.
This commit is contained in:
martinfalisse 2022-01-03 10:52:38 +01:00 committed by Andreas Kling
parent e824a2da90
commit 452150c632
2 changed files with 13 additions and 1 deletions

View file

@ -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,

View file

@ -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;