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:
parent
e371d6345b
commit
51f714de0f
@ -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;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ namespace ui
|
||||
{
|
||||
class ScrollPanel: public Panel
|
||||
{
|
||||
void CancelPanning();
|
||||
|
||||
protected:
|
||||
int scrollBarWidth;
|
||||
Point maxOffset;
|
||||
|
Loading…
Reference in New Issue
Block a user