Sticky scroll in menus

This commit is contained in:
Bertrand Songis
2019-11-04 15:31:04 +01:00
parent afe0216671
commit c744ee226a
2 changed files with 20 additions and 11 deletions
+12 -11
View File
@@ -171,10 +171,10 @@ void Window::scrollTo(Window * child)
coord_t bottom = offsetY + child->bottom();
if (top < scrollPositionY) {
setScrollPositionY(top - 5);
setScrollPositionY(pageHeight ? top - (top % pageHeight) : top - 5);
}
else if (bottom > scrollPositionY + height() - 5) {
setScrollPositionY(bottom - height() + 5);
setScrollPositionY(pageHeight ? top - (top % pageHeight) : bottom - height() + 5);
}
if (left < scrollPositionX) {
@@ -290,16 +290,17 @@ void Window::checkEvents()
}
#if defined(HARDWARE_TOUCH)
if (pageWidth && touchState.event != TE_SLIDE) {
coord_t relativeScrollPosition = scrollPositionX % pageWidth;
if (relativeScrollPosition) {
if (relativeScrollPosition > pageWidth / 2) {
setScrollPositionX(getScrollPositionX() - relativeScrollPosition + pageWidth);
invalidate();
if (touchState.event != TE_SLIDE) {
if (pageWidth) {
coord_t relativeScrollPosition = scrollPositionX % pageWidth;
if (relativeScrollPosition) {
setScrollPositionX(getScrollPositionX() - relativeScrollPosition + (relativeScrollPosition > pageWidth / 2 ? pageWidth : 0));
}
else {
setScrollPositionX(getScrollPositionX() - relativeScrollPosition);
invalidate();
}
if (pageHeight) {
coord_t relativeScrollPosition = scrollPositionY % pageHeight;
if (relativeScrollPosition) {
setScrollPositionY(getScrollPositionY() - relativeScrollPosition + (relativeScrollPosition > pageHeight / 2 ? pageHeight : 0));
}
}
}
+8
View File
@@ -226,10 +226,17 @@ class Window {
pageWidth = w;
}
void setPageHeight(coord_t h)
{
pageHeight = h;
}
uint8_t getPageIndex()
{
if (pageWidth)
return (getScrollPositionX() + (pageWidth / 2)) / pageWidth;
else if (pageHeight)
return (getScrollPositionX() + (pageHeight / 2)) / pageHeight;
else
return 0;
}
@@ -323,6 +330,7 @@ class Window {
coord_t innerWidth;
coord_t innerHeight;
coord_t pageWidth = 0;
coord_t pageHeight = 0;
coord_t scrollPositionX = 0;
coord_t scrollPositionY = 0;
WindowFlags windowFlags;