From a56360f78741f8de494fb18789599b2643ea22f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 1 Sep 2020 17:29:02 +0200 Subject: LibGUI: Implement the virtual ListView::scroll_into_view() Instead of shadowing the one from AbstractView. --- Libraries/LibGUI/ListView.cpp | 13 +++++++------ Libraries/LibGUI/ListView.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'Libraries/LibGUI') diff --git a/Libraries/LibGUI/ListView.cpp b/Libraries/LibGUI/ListView.cpp index 56f9963fc9..a5ac557131 100644 --- a/Libraries/LibGUI/ListView.cpp +++ b/Libraries/LibGUI/ListView.cpp @@ -208,7 +208,7 @@ void ListView::move_selection(int steps) if (model.is_valid(new_index)) { set_last_valid_hovered_index({}); selection().set(new_index); - scroll_into_view(new_index, Orientation::Vertical); + scroll_into_view(new_index, false, true); update(); } else { if (hover_highlighting() && m_last_valid_hovered_index.is_valid()) { @@ -252,7 +252,7 @@ void ListView::keydown_event(KeyEvent& event) } if (model.is_valid(new_index)) { selection().set(new_index); - scroll_into_view(new_index, Orientation::Vertical); + scroll_into_view(new_index, false, true); update(); } return; @@ -269,7 +269,7 @@ void ListView::keydown_event(KeyEvent& event) } if (model.is_valid(new_index)) { selection().set(new_index); - scroll_into_view(new_index, Orientation::Vertical); + scroll_into_view(new_index, false, true); update(); } return; @@ -282,10 +282,11 @@ void ListView::keydown_event(KeyEvent& event) return Widget::keydown_event(event); } -void ListView::scroll_into_view(const ModelIndex& index, Orientation orientation) +void ListView::scroll_into_view(const ModelIndex& index, bool scroll_horizontally, bool scroll_vertically) { - auto rect = content_rect(index.row()); - ScrollableWidget::scroll_into_view(rect, orientation); + if (!model()) + return; + ScrollableWidget::scroll_into_view(content_rect(index.row()), scroll_horizontally, scroll_vertically); } } diff --git a/Libraries/LibGUI/ListView.h b/Libraries/LibGUI/ListView.h index bb295116d0..15158d7f77 100644 --- a/Libraries/LibGUI/ListView.h +++ b/Libraries/LibGUI/ListView.h @@ -45,7 +45,7 @@ public: int horizontal_padding() const { return m_horizontal_padding; } - void scroll_into_view(const ModelIndex&, Orientation); + virtual void scroll_into_view(const ModelIndex& index, bool scroll_horizontally, bool scroll_vertically) override; Gfx::IntPoint adjusted_position(const Gfx::IntPoint&) const; -- cgit v1.2.3