Sticky scroll in menus
This commit is contained in:
+12
-11
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user