Skip to content

Commit

Permalink
Stop scrolling in ScrollPanels on mousedown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LBPHacker committed Apr 3, 2024
1 parent e371d63 commit 51f714d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/gui/interface/ScrollPanel.cpp
Expand Up @@ -75,6 +75,7 @@ void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button)
{
if (MouseDownInside)
{
CancelPanning();
if (isMouseInsideScrollbar)
{
scrollbarSelected = true;
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/interface/ScrollPanel.h
Expand Up @@ -7,6 +7,8 @@ namespace ui
{
class ScrollPanel: public Panel
{
void CancelPanning();

protected:
int scrollBarWidth;
Point maxOffset;
Expand Down

0 comments on commit 51f714d

Please sign in to comment.