diff --git a/radio/src/thirdparty/libopenui/src/roller.h b/radio/src/thirdparty/libopenui/src/roller.h index b2f567be8..76a948720 100644 --- a/radio/src/thirdparty/libopenui/src/roller.h +++ b/radio/src/thirdparty/libopenui/src/roller.h @@ -24,10 +24,12 @@ #include #include #include +#include #include "libopenui_globals.h" #include "libopenui_config.h" constexpr WindowFlags ROLLER_SEPARATION_LINES = (FORM_FLAGS_LAST << 1u); +constexpr coord_t SCROLL_POSITION_INVALIDATED = INT_MIN; class Roller: public Choice { public: @@ -106,6 +108,10 @@ class Roller: public Choice { lastEditMode = editMode; } + if (lastScrollPositionY == SCROLL_POSITION_INVALIDATED) { + updateScrollPositionFromValue(); + } + #if defined(HARDWARE_TOUCH) if (touchState.event != TE_SLIDE) { if (scrollPositionY != lastScrollPositionY) { @@ -115,10 +121,36 @@ class Roller: public Choice { #endif } + // virtual not needed until now + void setMin(int16_t value) + { + Choice::setMin(value); + invalidateScrollPosition(); + } + + // virtual not needed until now + void setMax(int16_t value) + { + Choice::setMax(value); + invalidateScrollPosition(); + } + + // virtual not needed until now + void setAvailableHandler(std::function handler) + { + Choice::setAvailableHandler(std::move(handler)); + invalidateScrollPosition(); + } + protected: - coord_t lastScrollPositionY = 0; + coord_t lastScrollPositionY = SCROLL_POSITION_INVALIDATED; bool lastEditMode = false; + void invalidateScrollPosition() + { + lastScrollPositionY = SCROLL_POSITION_INVALIDATED; + } + void updateScrollPositionFromValue() { setScrollPositionY(ROLLER_LINE_HEIGHT * (getIndexFromValue(this->getValue()) - 1));