Roller fix

This commit is contained in:
Bertrand Songis
2021-02-23 18:40:14 +01:00
parent 8d519c9fde
commit c7c36d0652
2 changed files with 12 additions and 7 deletions
@@ -61,6 +61,11 @@ inline int multDivRoundClosest(int v, int n, int d)
return divRoundClosest(v * n, d);
}
inline int mod(int k, int n)
{
return ((k %= n) < 0) ? k + n : k;
}
template<class T>
inline T sgn(T a)
{
+7 -7
View File
@@ -68,7 +68,7 @@ class Roller: public Choice
void paint(BitmapBuffer * dc) override
{
int32_t value = getValue();
auto valuesCount = getValuesCount();
auto valuesCount = (int)getValuesCount();
if (valuesCount == 0) {
return;
}
@@ -76,11 +76,10 @@ class Roller: public Choice
int index = (scrollPositionY - ROLLER_LINE_HEIGHT + 1) / ROLLER_LINE_HEIGHT;
coord_t y = index * ROLLER_LINE_HEIGHT;
coord_t yMax = scrollPositionY + 3 * ROLLER_LINE_HEIGHT;
while (index < 0)
index += valuesCount;
index = mod(index, valuesCount);
while (y < yMax) {
auto displayedValue = getValueFromIndex(index % valuesCount);
auto displayedValue = getValueFromIndex(index);
auto fgColor = DISABLE_COLOR;
if (value == displayedValue) {
@@ -99,7 +98,9 @@ class Roller: public Choice
dc->drawSolidHorizontalLine(0, y - 10, width(), DISABLE_COLOR);
}
index += 1;
if (++index == valuesCount)
index = 0;
y += ROLLER_LINE_HEIGHT;
}
}
@@ -167,10 +168,9 @@ class Roller: public Choice
lastScrollPositionY = scrollPositionY;
auto valuesCount = getValuesCount();
auto newValue = getValueFromIndex((((scrollPositionY / ROLLER_LINE_HEIGHT) + 1) + valuesCount) % valuesCount);
auto newValue = getValueFromIndex(mod((scrollPositionY / ROLLER_LINE_HEIGHT) + 1, valuesCount));
setValue(newValue);
invalidate();
}
};