From 51f714de0f72628d41ced7ad6aa172215bae3f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 28 Mar 2024 11:31:38 +0100 Subject: [PATCH] Stop scrolling in ScrollPanels on mousedown The goal was to let finger flicks that didn't qualify as panning commands cancel momentum scrolling. The final effect is that any click does, which is fine. --- src/gui/interface/ScrollPanel.cpp | 22 +++++++++++++++------- src/gui/interface/ScrollPanel.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp index 9eeb8e704a..542e230c1f 100644 --- a/src/gui/interface/ScrollPanel.cpp +++ b/src/gui/interface/ScrollPanel.cpp @@ -75,6 +75,7 @@ void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button) { if (MouseDownInside) { + CancelPanning(); if (isMouseInsideScrollbar) { scrollbarSelected = true; @@ -86,24 +87,31 @@ void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button) } } +void ScrollPanel::CancelPanning() +{ + panning = false; + panHistory = {}; + yScrollVel = 0; +} + void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button) { scrollbarSelected = false; - panning = false; + auto oldPanHistory = panHistory; + CancelPanning(); { - auto it = panHistory.end(); - while (it != panHistory.begin() && *(it - 1)) + auto it = oldPanHistory.end(); + while (it != oldPanHistory.begin() && *(it - 1)) { --it; } - if (it < panHistory.end()) + if (it < oldPanHistory.end()) { - auto offsetYDiff = panHistory.back()->offsetY - (*it)->offsetY; - auto tickDiff = panHistory.back()->ticks - (*it)->ticks; + auto offsetYDiff = oldPanHistory.back()->offsetY - (*it)->offsetY; + auto tickDiff = oldPanHistory.back()->ticks - (*it)->ticks; yScrollVel += offsetYDiff / tickDiff * (1000.f / Engine::Ref().GetFps()); } } - panHistory = {}; isMouseInsideScrollbarArea = false; scrollbarClickLocation = 0; } diff --git a/src/gui/interface/ScrollPanel.h b/src/gui/interface/ScrollPanel.h index fdd6a13213..94bbfa8d3a 100644 --- a/src/gui/interface/ScrollPanel.h +++ b/src/gui/interface/ScrollPanel.h @@ -7,6 +7,8 @@ namespace ui { class ScrollPanel: public Panel { + void CancelPanning(); + protected: int scrollBarWidth; Point maxOffset;