1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibGUI: Teach ColumnsView where indexes are placed (and scroll to them)

This makes the view to scroll when pressing arrow keys! :^)
This commit is contained in:
Karol Kosek 2022-12-28 00:36:34 +01:00 committed by Andreas Kling
parent 7e52daa542
commit 35e3df7f13
2 changed files with 22 additions and 0 deletions

View file

@ -435,6 +435,25 @@ void ColumnsView::move_cursor(CursorMovement movement, SelectionUpdate selection
set_cursor(new_index, selection_update);
}
Gfx::IntRect ColumnsView::index_content_rect(ModelIndex const& index)
{
int column_x = 0;
for (auto const& column : m_columns) {
if (column.parent_index == index.parent())
return { column_x, index.row() * item_height(), column.width, item_height() };
column_x += column.width + column_separator_width();
}
return {};
}
void ColumnsView::scroll_into_view(ModelIndex const& index, bool scroll_horizontally, bool scroll_vertically)
{
if (!model())
return;
AbstractScrollableWidget::scroll_into_view(index_content_rect(index), scroll_horizontally, scroll_vertically);
}
Gfx::IntRect ColumnsView::content_rect(ModelIndex const& index) const
{
if (!index.is_valid())