Bedtime. /Menu System

Menu System

Pre-built menu UI components

The menu system provides a complete solution for building settings screens and navigation hierarchies.

static void play_action(ui_menu_t* menu, ui_menu_node_t* entry) {
    my_model_t* m = ui_menu_ctx(menu);   // the ctx passed to ui_menu_create, at any depth
    ...
}
static void root_menu(ui_menu_t* menu) {   // the builder: runs at create and every ui_menu_show
    my_model_t* m = ui_menu_ctx(menu);
    ui_menu_add(menu, UI_ACTION("Play", play_action));
    ui_menu_add(menu, UI_PARAM("Volume", MenuNodeParam, &m->volume));
}
// init(): m->menu = ui_menu_create(m, root_menu);    a button: ui_menu_show(m->menu);

Style a menu once (type, position, width, rows - in any order): a submenu inherits the look of the level it was entered from and may change it, and "back" restores the parent's. The menu is modal while shown; BTN4/BTN5 hold go back / close, and closing hides it before the close callback (ui_menu_set_close_cb) runs - which may destroy it.

A pick list: UI_PICK(name, callback, index) entries, and UI_PICK_IDX(entry) in the callback.

ui_menu_t* ui_menu_create(void* app_ctx, ui_menu_sub_cb root_builder)

Create a menu instance

void*app_ctxApp context (typically os_app_t*)
ui_menu_sub_cbroot_builderRoot menu builder callback

Returns — Pointer to menu instance, or NULL on error

void ui_menu_destroy(ui_menu_t* menu)

Destroy a menu instance

ui_menu_t*menuMenu instance
void ui_menu_add(ui_menu_t* menu, ui_menu_node_t entry)

Add an entry to the menu

ui_menu_t*menuMenu instance
ui_menu_node_tentryMenu node entry
void* ui_menu_ctx(ui_menu_t* menu)

The context passed to ui_menu_create - at every depth (a submenu's own data is its entry's user_data)

ui_menu_t*menu
void ui_menu_rebuild(ui_menu_t* menu)

Rebuild current menu view

ui_menu_t*menuMenu instance
void ui_menu_show(ui_menu_t* menu)

Show the menu: re-runs the current level's builder (cursor kept) and takes input - modal, the app's on_input() receives nothing until it closes

ui_menu_t*menu
void ui_menu_hide(ui_menu_t* menu)

Hide menu (detach from widget layer)

ui_menu_t*menuMenu instance
bool ui_menu_is_visible(ui_menu_t* menu)

Check if menu is visible

ui_menu_t*menuMenu instance

Returns — true if visible