1
0
Fork 0

Codechange: Add OnScrollbarScroll window event, called when a scrollbar position changes.

pull/14293/head
Peter Nelson 2025-05-14 18:06:49 +01:00 committed by Peter Nelson
parent 321f7e8683
commit 780c26237f
3 changed files with 24 additions and 4 deletions

View File

@ -240,6 +240,7 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
if (changed) { if (changed) {
/* Position changed so refresh the window */ /* Position changed so refresh the window */
w->OnScrollbarScroll(sb->GetIndex());
w->SetDirty(); w->SetDirty();
} else { } else {
/* No change so only refresh this scrollbar */ /* No change so only refresh this scrollbar */

View File

@ -818,7 +818,10 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
if (nwid->type == NWID_VSCROLLBAR) { if (nwid->type == NWID_VSCROLLBAR) {
NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid); NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid);
if (sb->GetCount() > sb->GetCapacity()) { if (sb->GetCount() > sb->GetCapacity()) {
if (sb->UpdatePosition(wheel)) w->SetDirty(); if (sb->UpdatePosition(wheel)) {
w->OnScrollbarScroll(nwid->GetIndex());
w->SetDirty();
}
} }
return; return;
} }
@ -826,7 +829,10 @@ static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
/* Scroll the widget attached to the scrollbar. */ /* Scroll the widget attached to the scrollbar. */
Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr); Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr);
if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) { 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 (sb->disp_flags.Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
if (_scroller_click_timeout == 1) { if (_scroller_click_timeout == 1) {
_scroller_click_timeout = 3; _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; return;
} }
@ -2353,7 +2362,10 @@ static void HandleScrollbarScrolling(Window *w)
int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size)); int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size));
if (rtl) pos = range - pos; if (rtl) pos = range - pos;
if (sb->SetPosition(pos)) w->SetDirty(); if (sb->SetPosition(pos)) {
w->OnScrollbarScroll(w->mouse_capture_widget);
w->SetDirty();
}
} }
/** /**

View File

@ -711,6 +711,13 @@ public:
*/ */
virtual void OnScroll([[maybe_unused]] Point delta) {} 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 * The mouse is currently moving over the window or has just moved outside
* of the window. In the latter case pt is (-1, -1). * of the window. In the latter case pt is (-1, -1).