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();
|
coord_t bottom = offsetY + child->bottom();
|
||||||
|
|
||||||
if (top < scrollPositionY) {
|
if (top < scrollPositionY) {
|
||||||
setScrollPositionY(top - 5);
|
setScrollPositionY(pageHeight ? top - (top % pageHeight) : top - 5);
|
||||||
}
|
}
|
||||||
else if (bottom > scrollPositionY + height() - 5) {
|
else if (bottom > scrollPositionY + height() - 5) {
|
||||||
setScrollPositionY(bottom - height() + 5);
|
setScrollPositionY(pageHeight ? top - (top % pageHeight) : bottom - height() + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (left < scrollPositionX) {
|
if (left < scrollPositionX) {
|
||||||
@@ -290,16 +290,17 @@ void Window::checkEvents()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
if (pageWidth && touchState.event != TE_SLIDE) {
|
if (touchState.event != TE_SLIDE) {
|
||||||
coord_t relativeScrollPosition = scrollPositionX % pageWidth;
|
if (pageWidth) {
|
||||||
if (relativeScrollPosition) {
|
coord_t relativeScrollPosition = scrollPositionX % pageWidth;
|
||||||
if (relativeScrollPosition > pageWidth / 2) {
|
if (relativeScrollPosition) {
|
||||||
setScrollPositionX(getScrollPositionX() - relativeScrollPosition + pageWidth);
|
setScrollPositionX(getScrollPositionX() - relativeScrollPosition + (relativeScrollPosition > pageWidth / 2 ? pageWidth : 0));
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
setScrollPositionX(getScrollPositionX() - relativeScrollPosition);
|
if (pageHeight) {
|
||||||
invalidate();
|
coord_t relativeScrollPosition = scrollPositionY % pageHeight;
|
||||||
|
if (relativeScrollPosition) {
|
||||||
|
setScrollPositionY(getScrollPositionY() - relativeScrollPosition + (relativeScrollPosition > pageHeight / 2 ? pageHeight : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -226,10 +226,17 @@ class Window {
|
|||||||
pageWidth = w;
|
pageWidth = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPageHeight(coord_t h)
|
||||||
|
{
|
||||||
|
pageHeight = h;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t getPageIndex()
|
uint8_t getPageIndex()
|
||||||
{
|
{
|
||||||
if (pageWidth)
|
if (pageWidth)
|
||||||
return (getScrollPositionX() + (pageWidth / 2)) / pageWidth;
|
return (getScrollPositionX() + (pageWidth / 2)) / pageWidth;
|
||||||
|
else if (pageHeight)
|
||||||
|
return (getScrollPositionX() + (pageHeight / 2)) / pageHeight;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -323,6 +330,7 @@ class Window {
|
|||||||
coord_t innerWidth;
|
coord_t innerWidth;
|
||||||
coord_t innerHeight;
|
coord_t innerHeight;
|
||||||
coord_t pageWidth = 0;
|
coord_t pageWidth = 0;
|
||||||
|
coord_t pageHeight = 0;
|
||||||
coord_t scrollPositionX = 0;
|
coord_t scrollPositionX = 0;
|
||||||
coord_t scrollPositionY = 0;
|
coord_t scrollPositionY = 0;
|
||||||
WindowFlags windowFlags;
|
WindowFlags windowFlags;
|
||||||
|
|||||||
Reference in New Issue
Block a user