summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/menu.h68
1 files changed, 38 insertions, 30 deletions
diff --git a/apps/menu.h b/apps/menu.h
index 3d1bd43cb3..7e08ef5aac 100644
--- a/apps/menu.h
+++ b/apps/menu.h
@@ -38,6 +38,7 @@ enum menu_item_type {
38 MT_OLD_MENU, /* used so we can wrap the old menu api 38 MT_OLD_MENU, /* used so we can wrap the old menu api
39 around the new api. Noone else should use this */ 39 around the new api. Noone else should use this */
40}; 40};
41#define MENU_TYPE_MASK 0xF /* MT_* type */
41 42
42typedef int (*menu_function)(void); 43typedef int (*menu_function)(void);
43struct menu_func { 44struct menu_func {
@@ -49,11 +50,13 @@ struct menu_func {
49 void *param; /* passed to function_w_param */ 50 void *param; /* passed to function_w_param */
50}; 51};
51 52
52#define MENU_TYPE_MASK 0xF /* MT_* type */
53/* these next two are mutually exclusive */ 53/* these next two are mutually exclusive */
54#define MENU_HAS_DESC 0x10 54#define MENU_HAS_DESC 0x10
55#define MENU_DYNAMIC_DESC 0x20 55#define MENU_DYNAMIC_DESC 0x20 /* the name of this menu item is set by the \
56#define MENU_EXITAFTERTHISMENU 0x40 56 list_get_name callback */
57
58#define MENU_EXITAFTERTHISMENU 0x40 /* do_menu() will exiting out of any \
59 menu item with this flag set */
57 60
58/* Flags for MT_FUNCTION_CALL */ 61/* Flags for MT_FUNCTION_CALL */
59#define MENU_FUNC_USEPARAM 0x80 62#define MENU_FUNC_USEPARAM 0x80
@@ -118,17 +121,19 @@ bool do_setting_from_menu(const struct menu_item_ex *temp);
118/* Use this for settings which have a differnt title in their 121/* Use this for settings which have a differnt title in their
119 setting screen than in the menu (e.g scroll options */ 122 setting screen than in the menu (e.g scroll options */
120#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \ 123#define MENUITEM_SETTING_W_TEXT(name, var, str, callback ) \
121 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\ 124 static const struct menu_callback_with_desc name##__ = \
125 {callback,str, Icon_NOICON}; \
122 static const struct menu_item_ex name = \ 126 static const struct menu_item_ex name = \
123 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \ 127 {MT_SETTING_W_TEXT|MENU_HAS_DESC, {.variable = (void*)var }, \
124 {.callback_and_desc = & name##__}}; 128 {.callback_and_desc = & name##__}};
125 129
126/* Use this To create a list of NON-XLATABLE (for the time being) Strings 130/* Use this To create a list of Strings (or ID2P()'s )
127 When the user enters this list and selects one, the menu will exits 131 When the user enters this list and selects one, the menu will exits
128 and its return value will be the index of the chosen item */ 132 and its return value will be the index of the chosen item */
129#define MENUITEM_STRINGLIST(name, str, callback, ... ) \ 133#define MENUITEM_STRINGLIST(name, str, callback, ... ) \
130 static const char *name##_[] = {__VA_ARGS__}; \ 134 static const char *name##_[] = {__VA_ARGS__}; \
131 static const struct menu_callback_with_desc name##__ = {callback,str, Icon_NOICON};\ 135 static const struct menu_callback_with_desc name##__ = \
136 {callback,str, Icon_NOICON}; \
132 static const struct menu_item_ex name = \ 137 static const struct menu_item_ex name = \
133 {MT_RETURN_ID|MENU_HAS_DESC| \ 138 {MT_RETURN_ID|MENU_HAS_DESC| \
134 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ 139 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
@@ -137,54 +142,57 @@ bool do_setting_from_menu(const struct menu_item_ex *temp);
137 142
138/* returns a value associated with the item */ 143/* returns a value associated with the item */
139#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \ 144#define MENUITEM_RETURNVALUE(name, str, val, cb, icon) \
140 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \ 145 static const struct menu_callback_with_desc name##_ = {cb,str,icon}; \
141 static const struct menu_item_ex name = \ 146 static const struct menu_item_ex name = \
142 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \ 147 { MT_RETURN_VALUE|MENU_HAS_DESC, { .value = val}, \
143 {.callback_and_desc = & name##_}}; 148 {.callback_and_desc = & name##_}};
144 149
145/* same as above, except the item name is dynamic */ 150/* same as above, except the item name is dynamic */
146#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, text_cb_data, icon) \ 151#define MENUITEM_RETURNVALUE_DYNTEXT(name, val, cb, text_callback, \
147 static const struct menu_get_name_and_icon name##_ \ 152 text_cb_data, icon) \
148 = {cb,text_callback,text_cb_data,icon}; \ 153 static const struct menu_get_name_and_icon name##_ \
154 = {cb,text_callback,text_cb_data,icon}; \
149 static const struct menu_item_ex name = \ 155 static const struct menu_item_ex name = \
150 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \ 156 { MT_RETURN_VALUE|MENU_DYNAMIC_DESC, { .value = val}, \
151 {.menu_get_name_and_icon = & name##_}}; 157 {.menu_get_name_and_icon = & name##_}};
152 158
153/* Use this to put a function call into the menu. 159/* Use this to put a function call into the menu.
154 When the user selects this item the function will be run, 160 When the user selects this item the function will be run,
155 unless MENU_FUNC_IGNORE_RETVAL is set, the return value 161 if MENU_FUNC_CHECK_RETVAL is set, the return value
156 will be checked, returning 1 will exit do_menu(); */ 162 will be checked, returning 1 will exit do_menu();
157#define MENUITEM_FUNCTION(name, flags, str, func, param, \ 163 if MENU_FUNC_USEPARAM is set, param will be passed to the function */
158 callback, icon) \ 164#define MENUITEM_FUNCTION(name, flags, str, func, param, \
165 callback, icon) \
159 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \ 166 static const struct menu_callback_with_desc name##_ = {callback,str,icon}; \
160 static const struct menu_func name##__ = {{(void*)func}, param}; \ 167 static const struct menu_func name##__ = {{(void*)func}, param}; \
161 /* should be const, but recording_settings wont let us do that */ \ 168 /* should be const, but recording_settings wont let us do that */ \
162 const struct menu_item_ex name = \ 169 const struct menu_item_ex name = \
163 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \ 170 { MT_FUNCTION_CALL|MENU_HAS_DESC|flags, \
164 { .function = & name##__}, {.callback_and_desc = & name##_}}; 171 { .function = & name##__}, {.callback_and_desc = & name##_}};
165 172
166/* As above, except the text is dynamic */ 173/* As above, except the text is dynamic */
167#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \ 174#define MENUITEM_FUNCTION_DYNTEXT(name, flags, func, param, \
168 text_callback, text_cb_data, callback, icon) \ 175 text_callback, text_cb_data, callback, icon) \
169 static const struct menu_get_name_and_icon name##_ \ 176 static const struct menu_get_name_and_icon name##_ \
170 = {callback,text_callback,text_cb_data,icon}; \ 177 = {callback,text_callback,text_cb_data,icon}; \
171 static const struct menu_func name##__ = {{(void*)func}, param}; \ 178 static const struct menu_func name##__ = {{(void*)func}, param}; \
172 static const struct menu_item_ex name = \ 179 static const struct menu_item_ex name = \
173 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ 180 { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \
174 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; 181 { .function = & name##__}, {.menu_get_name_and_icon = & name##_}};
175 182
176/* Use this to actually create a menu. the ... argument is a list of pointers 183/* Use this to actually create a menu. the ... argument is a list of pointers
177 to any of the above macro'd variables. (It can also have other menus in the list. */ 184 to any of the above macro'd variables.
178#define MAKE_MENU( name, str, callback, icon, ... ) \ 185 (It can also have other menus in the list.) */
179 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ 186#define MAKE_MENU( name, str, callback, icon, ... ) \
187 static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \
180 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\ 188 static const struct menu_callback_with_desc name##__ = {callback,str,icon};\
181 const struct menu_item_ex name = \ 189 const struct menu_item_ex name = \
182 {MT_MENU|MENU_HAS_DESC| \ 190 {MT_MENU|MENU_HAS_DESC| \
183 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ 191 MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \
184 { (void*)name##_},{.callback_and_desc = & name##__}}; 192 { (void*)name##_},{.callback_and_desc = & name##__}};
185 193
186 194
187/* OLD API - only use if you really have to.. Ideally this will be dropped */ 195/* OLD API - This is only here for plugin compatability now, will be dropped ASAP */
188struct menu_item { 196struct menu_item {
189 unsigned char *desc; /* string or ID */ 197 unsigned char *desc; /* string or ID */
190 bool (*function) (void); /* return true if USB was connected */ 198 bool (*function) (void); /* return true if USB was connected */