1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 05:54:58 +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())

View file

@ -22,6 +22,8 @@ public:
virtual Gfx::IntRect content_rect(ModelIndex const&) const override;
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const&) const override;
virtual void scroll_into_view(ModelIndex const&, bool scroll_horizontally, bool scroll_vertically) override;
private:
ColumnsView();
virtual ~ColumnsView() override = default;
@ -54,6 +56,7 @@ private:
Optional<Column> column_at_event_position(Gfx::IntPoint) const;
ModelIndex index_at_event_position_in_column(Gfx::IntPoint, Column const&) const;
Gfx::IntRect index_content_rect(ModelIndex const&);
bool m_rubber_banding { false };
int m_rubber_band_origin { 0 };