mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
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.
This commit is contained in:
parent
938380e88b
commit
8eb8949d9c
2 changed files with 5 additions and 13 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue