From daff01132ae88dcaa3052eacab10eeac228e96bd Mon Sep 17 00:00:00 2001 From: forntoh Date: Sun, 18 Feb 2024 20:48:11 +0100 Subject: [PATCH] BugFix: After `setCursorPosition` navigation is broken Now the bottom and top are correctly computed, so that navigation works when `setCursorPosition` is called. --- src/LcdMenu.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/LcdMenu.h b/src/LcdMenu.h index ee76b250..b02a6bf8 100644 --- a/src/LcdMenu.h +++ b/src/LcdMenu.h @@ -856,7 +856,20 @@ class LcdMenu { * @param position */ void setCursorPosition(uint8_t position) { - this->cursorPosition = position; + uint8_t bottom = position; + bool isNotEnd = false; + + do { + isNotEnd = currentMenuTable[++bottom]->getType() != + MENU_ITEM_END_OF_MENU && + bottom < maxRows + 20; + } while (isNotEnd); + + uint8_t max = maxRows - 1; + + this->cursorPosition = position + 1; + this->bottom = constrain(cursorPosition + max, max, bottom - 1); + this->top = this->bottom - max; } /** * Update timer and turn off display on timeout