Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#167 Update condition to check if cursor is at the top and bottom. #170

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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
4 changes: 3 additions & 1 deletion src/MenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
};

/**
Expand Down
16 changes: 16 additions & 0 deletions src/utils/commandProccesors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#include <Arduino.h>

#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) {
Expand Down
Loading