diff --git a/src/widget.cpp b/src/widget.cpp index 82236b453d..c86c8f9938 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -240,6 +240,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in if (changed) { /* Position changed so refresh the window */ + w->OnScrollbarScroll(sb->GetIndex()); w->SetDirty(); } else { /* No change so only refresh this scrollbar */ diff --git a/src/window.cpp b/src/window.cpp index a70c78f884..094df6190e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -818,7 +818,10 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel) if (nwid->type == NWID_VSCROLLBAR) { NWidgetScrollbar *sb = static_cast(nwid); if (sb->GetCount() > sb->GetCapacity()) { - if (sb->UpdatePosition(wheel)) w->SetDirty(); + if (sb->UpdatePosition(wheel)) { + w->OnScrollbarScroll(nwid->GetIndex()); + w->SetDirty(); + } } return; } @@ -826,7 +829,10 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel) /* Scroll the widget attached to the scrollbar. */ Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr); if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) { - if (sb->UpdatePosition(wheel)) w->SetDirty(); + if (sb->UpdatePosition(wheel)) { + w->OnScrollbarScroll(nwid->GetScrollbarIndex()); + w->SetDirty(); + } } } @@ -2342,7 +2348,10 @@ static void HandleScrollbarScrolling(Window *w) if (sb->disp_flags.Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) { if (_scroller_click_timeout == 1) { _scroller_click_timeout = 3; - if (sb->UpdatePosition(rtl == sb->disp_flags.Test(NWidgetDisplayFlag::ScrollbarUp) ? 1 : -1)) w->SetDirty(); + if (sb->UpdatePosition(rtl == sb->disp_flags.Test(NWidgetDisplayFlag::ScrollbarUp) ? 1 : -1)) { + w->OnScrollbarScroll(w->mouse_capture_widget); + w->SetDirty(); + } } return; } @@ -2353,7 +2362,10 @@ static void HandleScrollbarScrolling(Window *w) int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size)); if (rtl) pos = range - pos; - if (sb->SetPosition(pos)) w->SetDirty(); + if (sb->SetPosition(pos)) { + w->OnScrollbarScroll(w->mouse_capture_widget); + w->SetDirty(); + } } /** diff --git a/src/window_gui.h b/src/window_gui.h index 4e42450777..6af90991e7 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -711,6 +711,13 @@ public: */ virtual void OnScroll([[maybe_unused]] Point delta) {} + /** + * Notify window that a scrollbar position has been updated. + * @note Only called when the user scrolls, not if a window moves its scrollbar. + * @param widget the scrollbar widget index. + */ + virtual void OnScrollbarScroll([[maybe_unused]] WidgetID widget) {} + /** * The mouse is currently moving over the window or has just moved outside * of the window. In the latter case pt is (-1, -1).