From c744ee226a2485eab1c4da4ba6bf6128d11b4eb8 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 4 Nov 2019 15:31:04 +0100 Subject: [PATCH] Sticky scroll in menus --- radio/src/thirdparty/libopenui/src/window.cpp | 23 ++++++++++--------- radio/src/thirdparty/libopenui/src/window.h | 8 +++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 56abd5977..9c151f722 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -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)); } } } diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 37a358a44..9bf4b000b 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -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;