tcMenu
Loading...
Searching...
No Matches
src
MenuHistoryNavigator.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3
* This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4
*/
5
12
#ifndef TCMENU_MENUHISTORYNAVIGATOR_H
13
#define TCMENU_MENUHISTORYNAVIGATOR_H
14
15
#include "
MenuItems.h
"
16
17
#ifndef NAV_ITEM_ARRAY_SIZE
18
#define NAV_ITEM_ARRAY_SIZE 4
19
#endif
20
21
namespace
tcnav {
22
class
NavigationListener
{
23
NavigationListener
* next =
nullptr
;
24
public
:
25
virtual
void
navigationHasChanged(
MenuItem
* newItem,
bool
completelyReset)=0;
26
NavigationListener
* getNext() {
return
next; }
27
void
setNext(
NavigationListener
* nxt) { next = nxt; }
28
};
29
30
class
MenuNavigationStore
{
31
private
:
32
MenuItem
* root;
33
MenuItem
* currentRoot;
34
MenuItem
* currentSub;
35
MenuItem
* navItems[NAV_ITEM_ARRAY_SIZE];
36
MenuItem
* activeItems[NAV_ITEM_ARRAY_SIZE];
37
NavigationListener
* navigationLister =
nullptr
;
38
uint8_t navIdx;
39
bool
currentIsCustom;
40
public
:
41
MenuNavigationStore
() =
default
;
42
43
void
addNavigationListener(
NavigationListener
* newListener);
44
void
clearNavigationListeners() { navigationLister =
nullptr
; }
45
46
void
triggerNavigationListener(
bool
completeReset);
47
51
MenuItem
*
getRoot
() {
return
root; }
55
MenuItem
*
getCurrentRoot
() {
return
currentRoot; }
60
MenuItem
*
getCurrentSubMenu
() {
return
currentSub; }
61
66
void
setRootItem
(
MenuItem
* item);
67
74
void
navigateTo
(
MenuItem
* activeItem,
MenuItem
* newRoot,
bool
custom);
75
80
MenuItem
*
popNavigationGetActive
();
81
82
bool
isShowingRoot();
83
87
int
getNavigationDepth
()
const
{
return
navIdx; }
88
94
MenuItem
*
getActiveAt
(uint8_t i) {
return
i < navIdx ? activeItems[i] :
nullptr
; }
95
101
MenuItem
*
getRootAt
(uint8_t i) {
return
i < navIdx ? navItems[i] :
nullptr
; }
102
104
void
resetStack
();
105
};
106
}
107
108
#endif
//TCMENU_MENUHISTORYNAVIGATOR_H
MenuItems.h
In TcMenu, MenuItem storage is shared between program memory and RAM. Usually each MenuItem has assoc...
MenuItem
Definition
MenuItems.h:329
tcnav::MenuNavigationStore
Definition
MenuHistoryNavigator.h:30
tcnav::MenuNavigationStore::resetStack
void resetStack()
Definition
MenuHistoryNavigator.cpp:60
tcnav::MenuNavigationStore::getRootAt
MenuItem * getRootAt(uint8_t i)
Definition
MenuHistoryNavigator.h:101
tcnav::MenuNavigationStore::navigateTo
void navigateTo(MenuItem *activeItem, MenuItem *newRoot, bool custom)
Definition
MenuHistoryNavigator.cpp:21
tcnav::MenuNavigationStore::getRoot
MenuItem * getRoot()
Definition
MenuHistoryNavigator.h:51
tcnav::MenuNavigationStore::setRootItem
void setRootItem(MenuItem *item)
Definition
MenuHistoryNavigator.cpp:12
tcnav::MenuNavigationStore::popNavigationGetActive
MenuItem * popNavigationGetActive()
Definition
MenuHistoryNavigator.cpp:38
tcnav::MenuNavigationStore::getCurrentSubMenu
MenuItem * getCurrentSubMenu()
Definition
MenuHistoryNavigator.h:60
tcnav::MenuNavigationStore::getCurrentRoot
MenuItem * getCurrentRoot()
Definition
MenuHistoryNavigator.h:55
tcnav::MenuNavigationStore::getActiveAt
MenuItem * getActiveAt(uint8_t i)
Definition
MenuHistoryNavigator.h:94
tcnav::MenuNavigationStore::getNavigationDepth
int getNavigationDepth() const
Definition
MenuHistoryNavigator.h:87
tcnav::NavigationListener
Definition
MenuHistoryNavigator.h:22