Skip to content

Commit

Permalink
BugFix: After setCursorPosition navigation is broken
Browse files Browse the repository at this point in the history
Now the bottom and top are correctly computed, so that navigation works when `setCursorPosition` is called.
  • Loading branch information
forntoh committed Feb 18, 2024
1 parent 63f8248 commit daff011
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/LcdMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit daff011

Please sign in to comment.