From f19e78bc1e6f2d997b406ef2321d0a49e2803817 Mon Sep 17 00:00:00 2001 From: forntoh Date: Fri, 3 May 2024 14:28:51 +0200 Subject: [PATCH 1/2] #167 Update condition to check if cursor is at the top and bottom. This change modifies the code to include a check for both top and bottom positions before printing the down arrow. --- src/LcdMenu.h | 2 +- src/MenuItem.h | 4 +++- src/utils/commandProccesors.h | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/LcdMenu.h b/src/LcdMenu.h index b02a6bf8..57451dbf 100644 --- a/src/LcdMenu.h +++ b/src/LcdMenu.h @@ -225,7 +225,7 @@ class LcdMenu { // // determine if cursor is at the top // - if (top == 1) { + if (top == 1 && bottom == maxRows) { // // Print the down arrow only // diff --git a/src/MenuItem.h b/src/MenuItem.h index 4ec07906..7f2ed259 100644 --- a/src/MenuItem.h +++ b/src/MenuItem.h @@ -193,7 +193,9 @@ class ItemHeader : public MenuItem { MenuItem** getSubMenu() override { return this->parent; }; - MenuItem* operator[](const uint8_t index) override { return parent[index]; } + MenuItem* operator[](const uint8_t index) override { + return getSubMenu()[index]; + } }; /** diff --git a/src/utils/commandProccesors.h b/src/utils/commandProccesors.h index 3a33f9bf..0d771e71 100644 --- a/src/utils/commandProccesors.h +++ b/src/utils/commandProccesors.h @@ -2,6 +2,22 @@ #include #ifdef MenuItem_H +/** + * Processes the given command on the LcdMenu object. + * + * @param menu The LcdMenu object on which the command is to be processed. + * @param cmd The command to be processed. + * @param upCmd The command for moving up in the menu. + * @param downCmd The command for moving down in the menu. + * @param enterCmd The command for entering/editing a value. + * @param backCmd The command for going back in the menu. + * @param leftCmd The command for moving left in the menu. + * @param rightCmd The command for moving right in the menu. + * + * @return true if the command is consumed, false otherwise. + * + * @throws None + */ bool processCommand(LcdMenu& menu, byte cmd, byte upCmd, byte downCmd, byte enterCmd, byte backCmd, byte leftCmd, byte rightCmd) { if (cmd == upCmd) { From 53c3b7187fd5dd82fb9d88c7d3eb8c3397846ac4 Mon Sep 17 00:00:00 2001 From: forntoh Date: Fri, 3 May 2024 14:53:04 +0200 Subject: [PATCH 2/2] Refactor arrow display logic and add position check function 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. --- src/LcdMenu.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/LcdMenu.h b/src/LcdMenu.h index 57451dbf..7da6df63 100644 --- a/src/LcdMenu.h +++ b/src/LcdMenu.h @@ -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 // @@ -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 // @@ -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; } /**