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#ifndef _MENU_H_
134#define _MENU_H_
135
136#include <stdint.h>
137#include <stdbool.h>
138#include "linked_list.h"
139#include "hdw-btn.h"
140#include "font.h"
141#include "settingsManager.h"
142
149typedef void (*menuCb)(const char* label, bool selected, uint32_t value);
150
151typedef struct _menu_t menu_t;
152
156typedef struct
157{
158 const char* label;
159 const char* const* options;
161 uint8_t numOptions;
162 int32_t currentOpt;
163 int32_t minSetting;
164 int32_t maxSetting;
165 const int32_t* settingVals;
167} menuItem_t;
168
183
185extern const char* mnuBackStr;
186
187menu_t* initMenu(const char* title, menuCb cbFunc) __attribute__((warn_unused_result));
188void deinitMenu(menu_t* menu);
189menu_t* startSubMenu(menu_t* menu, const char* label) __attribute__((warn_unused_result));
190menu_t* endSubMenu(menu_t* menu) __attribute__((warn_unused_result));
191menuItem_t* addSingleItemToMenu(menu_t* menu, const char* label);
192void removeSingleItemFromMenu(menu_t* menu, const char* label);
193void addMultiItemToMenu(menu_t* menu, const char* const* labels, uint8_t numLabels, uint8_t currentLabel);
194void removeMultiItemFromMenu(menu_t* menu, const char* const* labels);
195void addSettingsItemToMenu(menu_t* menu, const char* label, const settingParam_t* bounds, int32_t val);
196void removeSettingsItemFromMenu(menu_t* menu, const char* label);
197void addSettingsOptionsItemToMenu(menu_t* menu, const char* settingLabel, const char* const* optionLabels,
198 const int32_t* optionValues, uint8_t numOptions, const settingParam_t* bounds,
199 int32_t currentValue);
200void removeSettingsOptionsItemFromMenu(menu_t* menu, const char* const* optionLabels);
201
202menu_t* menuNavigateToItem(menu_t* menu, const char* label);
208menu_t* menuSetCurrentOption(menu_t* menu, int32_t value);
209
210menu_t* menuButton(menu_t* menu, buttonEvt_t evt) __attribute__((warn_unused_result));
211void setShowBattery(menu_t* menu, bool showBattery);
212
213#endif
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition hdw-btn.h:117
A doubly linked list with pointers to the first and last nodes.
Definition linked_list.h:87
A node in a doubly linked list with pointers to the previous and next values (which may be NULL),...
Definition linked_list.h:77
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:758
bool showBattery
true if the battery measurement should be shown. false by default
Definition menu.h:179
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:329
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:848
const int32_t * settingVals
The setting value options for settings-options items.
Definition menu.h:165
int batteryLevel
The current battery measurement.
Definition menu.h:181
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:791
uint8_t numOptions
The number of options for multi-select.
Definition menu.h:161
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:352
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:650
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:164
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:450
int32_t minSetting
The minimum value for settings items.
Definition menu.h:163
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:701
struct _menu_t menu_t
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition menu.h:151
const char * mnuBackStr
A string used to return to super-menus that says "Back".
Definition menu.c:16
list_t * items
A list_t of menu items to display.
Definition menu.h:176
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:574
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:174
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:503
void(* 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:149
menuCb cbFunc
The callback function to call when menu items are selected.
Definition menu.h:175
int32_t currentSetting
The current value for settings items.
Definition menu.h:166
node_t * currentItem
The currently selected menu item.
Definition menu.h:177
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:158
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:597
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:551
const char *const * options
The labels displayed if multi-select.
Definition menu.h:159
int32_t currentOpt
The current selected option for multi-select.
Definition menu.h:162
menu_t * parentMenu
The parent menu, may be NULL if this is not a submenu.
Definition menu.h:178
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:286
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:262
void 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:404
int32_t batteryReadTimer
A timer to read the battery every 10s.
Definition menu.h:180
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:218
menu_t * subMenu
A pointer to a submenu, maybe NULL for single-select and multi-select.
Definition menu.h:160
The underlying data for a menu. This fundamentally is a list of menuItem_t.
Definition menu.h:173
The underlying data for an item in a menu. The item may be a single-select, multi-select,...
Definition menu.h:157
Immutable data for a setting, including minimum, maximum, and default values, and the NVS key.
Definition settingsManager.h:99