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.
This commit is contained in:
Tamás Bálint Misius 2024-03-28 11:31:38 +01:00
parent e371d6345b
commit 51f714de0f
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 17 additions and 7 deletions

View File

@ -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;
}

View File

@ -7,6 +7,8 @@ namespace ui
{
class ScrollPanel: public Panel
{
void CancelPanning();
protected:
int scrollBarWidth;
Point maxOffset;