diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index 30f5fe1e1..3403845ed 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -104,16 +104,6 @@ class FormGroup: public FormField { void addField(FormField * field); - inline FormField * getFirstField() - { - return first; - } - - inline FormField * getLastField() - { - return last; - } - protected: FormField * first = nullptr; FormField * last = nullptr; diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 64360c71d..c79289c72 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -18,6 +18,7 @@ */ #include "window.h" +#include "touch.h" Window * Window::focusWindow = nullptr; std::list Window::trash; @@ -154,13 +155,18 @@ void Window::setScrollPositionY(coord_t value) void Window::scrollTo(Window * child) { + coord_t offsetX = 0; coord_t offsetY = 0; + Window * parent = child->getParent(); while (parent && parent != this) { + offsetX += parent->left(); offsetY += parent->top(); parent = parent->getParent(); } + coord_t left = offsetX + child->left(); + coord_t right = offsetX + child->right(); coord_t top = offsetY + child->top(); coord_t bottom = offsetY + child->bottom(); @@ -170,6 +176,13 @@ void Window::scrollTo(Window * child) else if (bottom > scrollPositionY + height() - 5) { setScrollPositionY(bottom - height() + 5); } + + if (left < scrollPositionX) { + setScrollPositionX(pageWidth ? left - (left % pageWidth) : left - 5); + } + else if (right > scrollPositionX + width() - 5) { + setScrollPositionX(pageWidth ? left - (left % pageWidth) : right - width() + 5); + } } void Window::fullPaint(BitmapBuffer * dc) @@ -275,6 +288,22 @@ void Window::checkEvents() if (windowFlags & REFRESH_ALWAYS) { invalidate(); } + +#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(); + } + else { + setScrollPositionX(getScrollPositionX() - relativeScrollPosition); + invalidate(); + } + } + } +#endif } void Window::onEvent(event_t event) diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 8abf7d2f3..14873ee55 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -164,11 +164,6 @@ class Window { invalidate(); } - coord_t getHeight() - { - return rect.h; - } - void setLeft(coord_t x) { rect.x = x; @@ -224,6 +219,19 @@ class Window { } } + void setPageWidth(coord_t w) + { + pageWidth = w; + } + + uint8_t getPageIndex() + { + if (pageWidth) + return (getScrollPositionX() + (pageWidth / 2)) / pageWidth; + else + return 0; + } + void setInnerHeight(coord_t h) { innerHeight = h; @@ -312,6 +320,7 @@ class Window { rect_t rect; coord_t innerWidth; coord_t innerHeight; + coord_t pageWidth = 0; coord_t scrollPositionX = 0; coord_t scrollPositionY = 0; WindowFlags windowFlags;