forked from jonblack/arduino-menusystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuSystem.h
102 lines (71 loc) · 1.81 KB
/
MenuSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
MenuSystem.h - Library for creating menu structures.
Created by Jon Black, August 8th 2011.
Released into the public domain.
License: LGPL 3
*/
#ifndef MENUSYSTEM_H
#define MENUSYSTEM_H
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define MAX_MENU_ITEMS 5
class MenuComponent
{
public:
MenuComponent(char* name);
void set_name(char* name);
char* get_name() const;
virtual MenuComponent* select() = 0;
protected:
char* _name;
};
class MenuItem : public MenuComponent
{
public:
MenuItem(char* name);
void set_select_function(void (*on_select)(MenuItem*));
virtual MenuComponent* select();
private:
void (*_on_select)(MenuItem*);
};
class Menu : public MenuComponent
{
public:
Menu(char* name);
boolean next(boolean loop=false);
boolean prev(boolean loop=false);
MenuComponent* activate();
virtual MenuComponent* select();
void add_item(MenuItem* pItem, void (*on_select)(MenuItem*));
Menu const* add_menu(Menu* pMenu);
void set_parent(Menu* pParent);
Menu const* get_parent() const;
MenuComponent const* get_selected() const;
MenuComponent const* get_menu_component(byte index) const;
byte get_num_menu_components() const;
byte get_cur_menu_component_num() const;
private:
MenuComponent* _p_sel_menu_component;
MenuComponent* _menu_components[MAX_MENU_ITEMS];
Menu* _p_parent;
byte _num_menu_components;
byte _cur_menu_component_num;
};
class MenuSystem
{
public:
MenuSystem();
boolean next(boolean loop=false);
boolean prev(boolean loop=false);
void select();
boolean back();
void set_root_menu(Menu* p_root_menu);
Menu const* get_current_menu() const;
private:
Menu* _p_root_menu;
Menu* _p_curr_menu;
};
#endif