DCC-EX Simple Throttle
Simple throttle for a DCC-EX CommandStation
Loading...
Searching...
No Matches
/home/runner/work/DCCEXSimpleThrottle/DCCEXSimpleThrottle/BaseMenu.h
Go to the documentation of this file.
1/*
2 * © 2024 Peter Cole
3 * © 2023 Peter Cole
4 *
5 * This is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * It is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this code. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#ifndef BASEMENU_H
20#define BASEMENU_H
21
22#include "BaseMenuItem.h"
23#include "Defines.h"
24#include "DisplayInterface.h"
25#include "EventManager.h"
28#include <Arduino.h>
29
31class BaseMenu {
32public:
36
40
43 void displayMenu(DisplayInterface *displayInterface);
44
47 void setMenuName(const char *name);
48
51 const char *getMenuName();
52
55 void addItem(BaseMenuItem *menuItem);
56
60
64 BaseMenuItem *getMenuItemAtIndex(uint8_t index);
65
68 uint8_t getMenuItemCount();
69
72 uint8_t getSelectedItemIndex();
73
77
80 void setEventManager(EventManager *eventManager);
81
85
86private:
87 const char *_name = nullptr; // Name of this menu
88 BaseMenuItem *_firstMenuItem = nullptr; // Pointer to the first menu item in the linked list
89 uint8_t _menuItemCount = 0; // Count of menu items associated with this menu
90 uint8_t _currentItemIndex = 0; // Incrementing index to ensure each menu item has a unique index
91 uint8_t _selectedItemIndex = 0; // Index of the item currently selected by the user
92 bool _selectionChanged = false; // Flag if user has selected a different item
93 EventManager *_eventManager = nullptr; // pointer to the application event manager
94};
95
96#endif // MENU_H
UserConfirmationAction
User confirmation action data types available.
Definition UserConfirmationInterface.h:23
UserSelectionAction
User selection action data types available.
Definition UserSelectionInterface.h:23
Base class for all menu item types, and all menu item types must inherit from this....
Definition BaseMenuItem.h:28
Class for maintaining a linked list of menu items to form a menu.
Definition BaseMenu.h:31
void setEventManager(EventManager *eventManager)
Set the application's event manager instance.
Definition BaseMenu.cpp:92
BaseMenuItem * _firstMenuItem
Definition BaseMenu.h:88
bool _selectionChanged
Definition BaseMenu.h:92
uint8_t _selectedItemIndex
Definition BaseMenu.h:91
void handleUserSelectionAction(UserSelectionAction action)
Method to respond to user selection actions.
Definition BaseMenu.cpp:21
const char * _name
Definition BaseMenu.h:87
uint8_t _currentItemIndex
Definition BaseMenu.h:90
void displayMenu(DisplayInterface *displayInterface)
Method to display the menu on screen.
Definition BaseMenu.cpp:49
virtual void handleUserConfirmationAction(UserConfirmationAction action)=0
Implement this method to respond to user confirmation actions.
uint8_t _menuItemCount
Definition BaseMenu.h:89
BaseMenuItem * getMenuItemAtIndex(uint8_t index)
Get the menu item at the specified index.
Definition BaseMenu.cpp:73
uint8_t getMenuItemCount()
Get the number of menu items associated with this menu.
Definition BaseMenu.cpp:86
BaseMenuItem * getFirstMenuItem()
Get the first menu item associated with this menu.
Definition BaseMenu.cpp:71
EventManager * _eventManager
Definition BaseMenu.h:93
EventManager * getEventManager()
Get the application's event manager instance.
Definition BaseMenu.cpp:94
bool getSelectionChanged()
Check if the user selection has changed.
Definition BaseMenu.cpp:90
uint8_t getSelectedItemIndex()
Get the index of the currently selected menu item.
Definition BaseMenu.cpp:88
void setMenuName(const char *name)
Set the name of this menu.
Definition BaseMenu.cpp:53
const char * getMenuName()
Get the name of this menu.
Definition BaseMenu.cpp:55
void addItem(BaseMenuItem *menuItem)
Add a menu item to this menu.
Definition BaseMenu.cpp:57
Interface class to abstract construction of what is displayed on screen from the physical implementat...
Definition DisplayInterface.h:29
Class to centrally manage all events for the application Exposes methods to register subscribers that...
Definition EventManager.h:28