Skip to content

Commit 4a7f83c

Browse files
committed
Fields, Choose and Toggle templates added
menuField: change value of numeric variable menuChoose: Use menu navigation to select variable value menuToggle: 'click' to change variable value cycling a list a values menuValue: menu prompt holding a value for variable set TODO: avoid unnecessary redraw
1 parent 903aa38 commit 4a7f83c

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

menu.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,42 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
9999
};\
100100
menu id (text,sizeof(id##_data)/sizeof(prompt*),id##_data);
101101

102+
/*#define CHOOSE(type,id,text,...)\
103+
FOR_EACH(menuValue<type> DECL_VALUE,__VA_ARGS__)\
104+
menuValue<type>* const id##_data[]={\
105+
FOR_EACH(DEF,__VA_ARGS__)\
106+
};\
107+
menuChoice<type> id (text,sizeof(id##_data)/sizeof(prompt*),id##_data);*/
108+
109+
#define CHOOSE(target,id,text,...)\
110+
FOR_EACH(menuValue<typeof(target)> DECL_VALUE,__VA_ARGS__)\
111+
menuValue<typeof(target)>* const id##_data[]={\
112+
FOR_EACH(DEF,__VA_ARGS__)\
113+
};\
114+
menuChoice<typeof(target)> id (text,sizeof(id##_data)/sizeof(prompt*),id##_data,target);
115+
116+
#define TOGGLE(target,id,text,...)\
117+
FOR_EACH(menuValue<typeof(target)> DECL_VALUE,__VA_ARGS__)\
118+
menuValue<typeof(target)>* const id##_data[]={\
119+
FOR_EACH(DEF,__VA_ARGS__)\
120+
};\
121+
menuToggle<typeof(target)> id (text,sizeof(id##_data)/sizeof(prompt*),id##_data,target);
122+
102123
#define OP(...) OP_(__COUNTER__,__VA_ARGS__)
103124
#define FIELD(...) FIELD_(__COUNTER__,__VA_ARGS__)
125+
#define VALUE(...) VALUE_(__COUNTER__,__VA_ARGS__)
104126

105127
#define DECL_OP_(cnt,...) prompt op##cnt(__VA_ARGS__);
106128
#define DECL_FIELD_(cnt,type,...) menuField<type> _menuField##cnt(__VA_ARGS__);
107129
#define DECL_SUBMENU(id)
130+
#define DECL_VALUE(...) _##__VA_ARGS__
131+
#define _VALUE_(cnt,...) choice##cnt(__VA_ARGS__);
108132

109133
#define DEF_OP_(cnt,...) &op##cnt
110134
#define DEF_FIELD_(cnt,type,...) &_menuField##cnt
111135
#define DEF_SUBMENU(id) &id
112-
136+
#define DEF_VALUE(id) &id
137+
#define DEF_VALUE_(cnt,...) &choice##cnt
113138

114139
/////////////////////////////////////////////////////////
115140
// menu pure virtual output device, use derived
@@ -168,17 +193,16 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
168193
class prompt {
169194
public:
170195
const char *text;
171-
promptAction action;
196+
static void nothing() {}
197+
promptAction action=nothing;
172198
bool enabled;
173199
inline prompt(const char * text):text(text),enabled(true) {}
174200
inline prompt(const char * text,promptAction action)
175201
:text(text),action(action),enabled(true) {}
176202
virtual size_t printTo(Print& p) {
177-
//Serial<<"printing prompt"<<endl;
178203
p.print(text);return strlen(text);
179204
}
180205
virtual void activate(menuOut& p,Stream&c,bool) {
181-
//Serial<<"activating prompt "<<text<<endl;
182206
action(*this,p,c);
183207
}
184208
};

0 commit comments

Comments
 (0)