From 07b692e33055fa2adccb6f03f8656311cd7924a1 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 29 Dec 2021 17:16:58 +1100 Subject: [PATCH] Recalculate scroll size on value change --- source/Core/Src/gui.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index bbae1d7c..d6390419 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -882,21 +882,22 @@ void gui_Menu(const menuitem *menu) { Exiting, }; - uint8_t currentScreen = 0; - TickType_t autoRepeatTimer = 0; - TickType_t autoRepeatAcceleration = 0; - bool earlyExit = false; - bool lcdRefresh = true; - ButtonState lastButtonState = BUTTON_NONE; - uint8_t scrollContentSize = gui_getMenuLength(menu); - bool scrollBlink = false; - bool lastValue = false; - NavState navState = NavState::Entering; + uint8_t currentScreen = 0; + TickType_t autoRepeatTimer = 0; + TickType_t autoRepeatAcceleration = 0; + bool earlyExit = false; + bool lcdRefresh = true; + + ButtonState lastButtonState = BUTTON_NONE; + uint8_t scrollContentSize = gui_getMenuLength(menu); + bool scrollBlink = false; + bool lastValue = false; + NavState navState = NavState::Entering; ScrollMessage scrollMessage; while ((menu[currentScreen].draw != nullptr) && earlyExit == false) { - + bool valueChanged = false; // Handle menu transition: if (navState != NavState::Idle) { // Check if this menu item shall be skipped. If it shall be skipped, @@ -971,6 +972,7 @@ void gui_Menu(const menuitem *menu) { auto callIncrementHandler = [&]() { wasInGuiMenu = false; + valueChanged = true; bool res = false; if ((int)menu[currentScreen].autoSettingOption < (int)SettingsOptions::SettingsOptionsLength) { res = nextSettingValue(menu[currentScreen].autoSettingOption); @@ -1046,6 +1048,10 @@ void gui_Menu(const menuitem *menu) { earlyExit = true; scrollMessage.reset(); } + if (valueChanged) { + // If user changed value, update the scroll content size + scrollContentSize = gui_getMenuLength(menu); + } } }