Skip to content

Commit

Permalink
Refactor arrow display logic and add position check function
Browse files Browse the repository at this point in the history
Improved arrow display conditions based on cursor position to show correct arrows. Added a new function to check if an item at a specific position is at the end of the menu items.
  • Loading branch information
forntoh committed May 3, 2024
1 parent f19e78b commit 53c3b71
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/LcdMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class LcdMenu {
//
// determine if cursor is at the top
//
if (top == 1 && bottom == maxRows) {
if (top == 1 && !isAtTheEnd(bottom)) {
//
// Print the down arrow only
//
Expand All @@ -242,7 +242,7 @@ class LcdMenu {
//
lcd->setCursor(maxCols - 1, 0);
lcd->write(byte(0));
} else if (isAtTheEnd()) {
} else if (isAtTheEnd() && top != 1) {
//
// Print the up arrow only
//
Expand All @@ -263,8 +263,13 @@ class LcdMenu {
* Check if the cursor is at the end of the menu items
* @return true : `boolean` if it is at the end
*/
boolean isAtTheEnd() {
return currentMenuTable[cursorPosition + 1]->getType() ==
boolean isAtTheEnd() { return isAtTheEnd(cursorPosition); }
/**
* Check if the item at [position] is at the end of the menu items
* @return true : `boolean` if it is at the end
*/
boolean isAtTheEnd(uint8_t position) {
return currentMenuTable[position + 1]->getType() ==
MENU_ITEM_END_OF_MENU;
}
/**
Expand Down

0 comments on commit 53c3b71

Please sign in to comment.