gui: make kinetic scrolling deceleration more awesome
Change-Id: Ia674676c847e429c41ddbe6de3e1778c3d5c8302
diff --git a/gui/scrolllist.cpp b/gui/scrolllist.cpp
index 05141b1..8d9ab42 100644
--- a/gui/scrolllist.cpp
+++ b/gui/scrolllist.cpp
@@ -27,9 +27,8 @@
#include "objects.hpp"
#include "../data.hpp"
-const int SCROLLING_SPEED_DECREMENT = 6; // friction
-const int SCROLLING_FLOOR = 10; // minimum pixels for scrolling to start or stop
-const int SCROLLING_MULTIPLIER = 1; // initial speed of kinetic scrolling
+const float SCROLLING_SPEED_DECREMENT = 0.9; // friction
+const int SCROLLING_FLOOR = 2; // minimum pixels for scrolling to stop
const float SCROLLING_SPEED_LIMIT = 2.5; // maximum number of items to scroll per update
GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
@@ -367,6 +366,7 @@
// Handle kinetic scrolling
int maxScrollDistance = actualItemHeight * SCROLLING_SPEED_LIMIT;
+ int oldScrollingSpeed = scrollingSpeed;
if (scrollingSpeed == 0) {
// Do nothing
return 0;
@@ -375,13 +375,17 @@
y_offset += scrollingSpeed;
else
y_offset += maxScrollDistance;
- scrollingSpeed -= SCROLLING_SPEED_DECREMENT;
+ scrollingSpeed *= SCROLLING_SPEED_DECREMENT;
+ if (scrollingSpeed == oldScrollingSpeed)
+ --scrollingSpeed;
} else if (scrollingSpeed < 0) {
if (abs(scrollingSpeed) < maxScrollDistance)
y_offset += scrollingSpeed;
else
y_offset -= maxScrollDistance;
- scrollingSpeed += SCROLLING_SPEED_DECREMENT;
+ scrollingSpeed *= SCROLLING_SPEED_DECREMENT;
+ if (scrollingSpeed == oldScrollingSpeed)
+ ++scrollingSpeed;
}
if (abs(scrollingSpeed) < SCROLLING_FLOOR)
scrollingSpeed = 0;
@@ -506,9 +510,7 @@
} else {
// Start kinetic scrolling
scrollingSpeed = lastY - last2Y;
- if (abs(scrollingSpeed) > SCROLLING_FLOOR)
- scrollingSpeed *= SCROLLING_MULTIPLIER;
- else
+ if (abs(scrollingSpeed) < touchDebounce)
scrollingSpeed = 0;
}
case TOUCH_REPEAT: