From 70885a3dee2a2de3cd099b3395823dadc544725e Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 27 Dec 2022 23:02:31 +0100 Subject: [PATCH] LibGUI: Automatically scroll to a new column on adding it in ColumnsView --- Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp | 5 +++++ Userland/Libraries/LibGUI/AbstractScrollableWidget.h | 1 + Userland/Libraries/LibGUI/ColumnsView.cpp | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp b/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp index bb83b024f7..38aa5405c7 100644 --- a/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp +++ b/Userland/Libraries/LibGUI/AbstractScrollableWidget.cpp @@ -303,6 +303,11 @@ void AbstractScrollableWidget::scroll_to_bottom() scroll_into_view({ 0, content_height(), 0, 0 }, Orientation::Vertical); } +void AbstractScrollableWidget::scroll_to_right() +{ + scroll_into_view({ content_width(), 0, 0, 0 }, Orientation::Horizontal); +} + void AbstractScrollableWidget::set_automatic_scrolling_timer_active(bool active) { if (active == m_active_scrolling_enabled) diff --git a/Userland/Libraries/LibGUI/AbstractScrollableWidget.h b/Userland/Libraries/LibGUI/AbstractScrollableWidget.h index a3368ac6af..aca5b93eef 100644 --- a/Userland/Libraries/LibGUI/AbstractScrollableWidget.h +++ b/Userland/Libraries/LibGUI/AbstractScrollableWidget.h @@ -56,6 +56,7 @@ public: void scroll_to_top(); void scroll_to_bottom(); + void scroll_to_right(); void update_scrollbar_ranges(); void set_automatic_scrolling_timer_active(bool); diff --git a/Userland/Libraries/LibGUI/ColumnsView.cpp b/Userland/Libraries/LibGUI/ColumnsView.cpp index a4adb238f4..cf1b6caa2c 100644 --- a/Userland/Libraries/LibGUI/ColumnsView.cpp +++ b/Userland/Libraries/LibGUI/ColumnsView.cpp @@ -205,6 +205,10 @@ void ColumnsView::push_column(ModelIndex const& parent_index) dbgln("Adding a new column"); m_columns.append({ parent_index, 0 }); update_column_sizes(); + + // FIXME: Find a way not to jump the view so much when changing folders within the same directory. + scroll_to_right(); + update(); }