Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
menu.h
Go to the documentation of this file.
1
133
134#ifndef _MENU_H_
135#define _MENU_H_
136
137#include <stdint.h>
138#include <stdbool.h>
139#include "linked_list.h"
140#include "hdw-btn.h"
141#include "font.h"
142#include "settingsManager.h"
143
151typedef bool (*menuCb)(const char* label, bool selected, uint32_t value);
152
153typedef struct _menu_t menu_t;
154
158typedef struct
159{
160 const char* label;
161 const char* const* options;
163 uint8_t numOptions;
164 int32_t currentOpt;
165 int32_t minSetting;
166 int32_t maxSetting;
167 const int32_t* settingVals;
169} menuItem_t;
170
185
187extern const char* mnuBackStr;
188
189menu_t* initMenu(const char* title, menuCb cbFunc) __attribute__((warn_unused_result));
190void deinitMenu(menu_t* menu);
191menu_t* startSubMenu(menu_t* menu, const char* label) __attribute__((warn_unused_result));
192menu_t* endSubMenu(menu_t* menu) __attribute__((warn_unused_result));
193menuItem_t* addSingleItemToMenu(menu_t* menu, const char* label);
194menuItem_t* insertSingleItemToMenuAfter(menu_t* menu, const char* newLabel, const char* afterLabel);
195void removeSingleItemFromMenu(menu_t* menu, const char* label);
196void addMultiItemToMenu(menu_t* menu, const char* const* labels, uint8_t numLabels, uint8_t currentLabel);
197void removeMultiItemFromMenu(menu_t* menu, const char* const* labels);
198void addSettingsItemToMenu(menu_t* menu, const char* label, const settingParam_t* bounds, int32_t val);
199void removeSettingsItemFromMenu(menu_t* menu, const char* label);
200menuItem_t* addSettingsOptionsItemToMenu(menu_t* menu, const char* settingLabel, const char* const* optionLabels,
201 const int32_t* optionValues, uint8_t numOptions, const settingParam_t* bounds,
202 int32_t currentValue);
203void removeSettingsOptionsItemFromMenu(menu_t* menu, const char* const* optionLabels);
204
206menu_t* menuNavigateToItem(menu_t* menu, const char* label);
212menu_t* menuSetCurrentOption(menu_t* menu, int32_t value);
213
214menu_t* menuButton(menu_t* menu, buttonEvt_t evt) __attribute__((warn_unused_result));
215void setShowBattery(menu_t* menu, bool showBattery);
216
217#endif
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition hdw-btn.h:117
struct node node_t
A node in a doubly linked list with pointers to the previous and next values (which may be NULL),...
A doubly linked list with pointers to the first and last nodes.
Definition linked_list.h:87
const char * mnuBackStr
A string used to return to super-menus that says "Back".
Definition menu.c:16
menu_t * menuSetCurrentOption(menu_t *menu, int32_t value)
Performs the equivalent of scrolling to the given setting value or option index for the currently sel...
Definition menu.c:841
bool showBattery
true if the battery measurement should be shown. false by default
Definition menu.h:181
void addSettingsItemToMenu(menu_t *menu, const char *label, const settingParam_t *bounds, int32_t val)
Add a settings entry to the menu. A settings entry is left-right scrollable where an integer setting ...
Definition menu.c:371
void setShowBattery(menu_t *menu, bool showBattery)
Show or hide the battery on the menu. This should be called from the root menu after the menu is cons...
Definition menu.c:931
const int32_t * settingVals
The setting value options for settings-options items.
Definition menu.h:167
int batteryLevel
The current battery measurement.
Definition menu.h:183
bool(* menuCb)(const char *label, bool selected, uint32_t value)
A callback which is called when a menu changes or items are selected.
Definition menu.h:151
menu_t * menuButton(menu_t *menu, buttonEvt_t evt)
This must be called to pass button event from the Swadge mode to the menu. If a button is passed here...
Definition menu.c:874
uint8_t numOptions
The number of options for multi-select.
Definition menu.h:163
void removeSettingsItemFromMenu(menu_t *menu, const char *label)
Remove a settings item entry from the menu. This item is removed by pointer, not by doing any string ...
Definition menu.c:395
void deinitMenu(menu_t *menu)
Deinitialize a menu and all connected menus, including submenus and parent menus. This frees memory a...
Definition menu.c:68
menu_t * menuNavigateToNextOption(menu_t *menu)
Navigate to the next option in a menu item. This is equivalent to pressing the RIGHT button.
Definition menu.c:727
menu_t * initMenu(const char *title, menuCb cbFunc)
Initialize and return an empty menu. A menu is a collection of vertically scrollable rows....
Definition menu.c:49
int32_t maxSetting
The maximum value for settings items.
Definition menu.h:166
void removeSettingsOptionsItemFromMenu(menu_t *menu, const char *const *optionLabels)
Remove a settings options item entry from the menu. This item is removed by pointer,...
Definition menu.c:496
int32_t minSetting
The minimum value for settings items.
Definition menu.h:165
menu_t * menuSelectCurrentItem(menu_t *menu)
Select the current item in a menu item. This is equivalent to pressing the A button.
Definition menu.c:782
menuItem_t * addSettingsOptionsItemToMenu(menu_t *menu, const char *settingLabel, const char *const *optionLabels, const int32_t *optionValues, uint8_t numOptions, const settingParam_t *bounds, int32_t currentValue)
Adds a settings item entry to the menu with a specific list of options. The entry will be left-right ...
Definition menu.c:448
struct _menu_t menu_t
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition menu.h:153
menuItem_t * insertSingleItemToMenuAfter(menu_t *menu, const char *newLabel, const char *afterLabel)
Add a single item entry to the menu after a given label. When this item is selected,...
Definition menu.c:221
list_t * items
A list_t of menu items to display.
Definition menu.h:178
menu_t * menuNavigateToNextItem(menu_t *menu)
Navigate to the next item in the menu. This is equivalent to pressing the DOWN button.
Definition menu.c:643
menu_t * startSubMenu(menu_t *menu, const char *label)
Add a submenu item to the menu. When this item is select, the submenu is rendered....
Definition menu.c:131
const char * title
The title for this menu.
Definition menu.h:176
menu_t * menuNavigateToItem(menu_t *menu, const char *label)
Changes the selected item to the one with the given label, just as though it were scrolled to.
Definition menu.c:569
menuCb cbFunc
The callback function to call when menu items are selected.
Definition menu.h:177
int32_t currentSetting
The current value for settings items.
Definition menu.h:168
node_t * currentItem
The currently selected menu item.
Definition menu.h:179
menu_t * endSubMenu(menu_t *menu)
Finish adding items to a submenu and resume adding items to the parent menu. This will automatically ...
Definition menu.c:171
const char * label
The label displayed if single-select or submenu.
Definition menu.h:160
menu_t * menuNavigateToPrevOption(menu_t *menu)
Navigate to the previous option in a menu item. This is equivalent to pressing the LEFT button.
Definition menu.c:670
menu_t * menuNavigateToTopItem(menu_t *menu)
Navigate to the first item in a menu, just as though it were scrolled to.
Definition menu.c:548
menu_t * menuNavigateToPrevItem(menu_t *menu)
Navigate to the previous item in the menu. This is equivalent to pressing the UP button.
Definition menu.c:617
const char *const * options
The labels displayed if multi-select.
Definition menu.h:161
int32_t currentOpt
The current selected option for multi-select.
Definition menu.h:164
menu_t * parentMenu
The parent menu, may be NULL if this is not a submenu.
Definition menu.h:180
void removeMultiItemFromMenu(menu_t *menu, const char *const *labels)
Remove a multi item entry from the menu. This item is removed by pointer, not by doing any string com...
Definition menu.c:328
menuItem_t * addSingleItemToMenu(menu_t *menu, const char *label)
Add a single item entry to the menu. When this item is selected, the menuCb callback is called with t...
Definition menu.c:193
void addMultiItemToMenu(menu_t *menu, const char *const *labels, uint8_t numLabels, uint8_t currentLabel)
Add a multiple item entry to the menu. The multiple items exist in a single entry and are left-right ...
Definition menu.c:304
int32_t batteryReadTimer
A timer to read the battery every 10s.
Definition menu.h:182
void removeSingleItemFromMenu(menu_t *menu, const char *label)
Remove a single item entry from the menu. This item is removed by pointer, not by doing a string comp...
Definition menu.c:260
menu_t * subMenu
A pointer to a submenu, maybe NULL for single-select and multi-select.
Definition menu.h:162
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition menu.h:175
The underlying data for an item in a menu. The item may be a single-select, multi-select,...
Definition menu.h:159
Immutable data for a setting, including minimum, maximum, and default values, and the NVS key.
Definition settingsManager.h:100