Skip to content

File syn_menu.h

FileList > src > syntropic > ui > syn_menu.h

Go to the source code of this file

Tree-structured menu system. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_Menu
Menu runtime state — navigation stack and rendering.
struct SYN_MenuItem
Menu item — label + action type + union payload.
struct SYN_MenuValueCfg
Value adjustment config for SYN_MENU_ACTION_VALUE items.

Public Types

Type Name
enum SYN_MenuAction
Menu item action types.
typedef void(* SYN_MenuRenderFn
Menu render callback — called after each navigation change.

Public Functions

Type Name
void syn_menu_back (SYN_Menu * menu)
Back: leave submenu or exit edit mode.
void syn_menu_down (SYN_Menu * menu)
Move selection down. In edit mode: decrement value.
void syn_menu_enter (SYN_Menu * menu)
Enter: navigate into submenu, toggle, start editing, or fire callback.
void syn_menu_init (SYN_Menu * menu, const SYN_MenuItem * root, SYN_MenuRenderFn render, void * ctx)
Initialize menu system.
void syn_menu_render (const SYN_Menu * menu)
Force a render (e.g. after external state change).
void syn_menu_up (SYN_Menu * menu)
Move selection up. In edit mode: increment value.

Public Static Functions

Type Name
uint8_t syn_menu_item_count (const SYN_Menu * menu)
Get the number of items in the current menu level.
const SYN_MenuItem * syn_menu_selected_item (const SYN_Menu * menu)
Get the currently selected item.

Macros

Type Name
define SYN_MENU_CALLBACK (lbl, fn, c) /* multi line expression */
Define a callback action item.
define SYN_MENU_MAX_DEPTH 8
define SYN_MENU_ROOT (name, items) static const [**SYN\_MenuItem**](structSYN__MenuItem.md) name = [**SYN\_MENU\_SUBMENU**](syn__menu_8h.md#define-syn_menu_submenu)(#name, items)
Define the root menu.
define SYN_MENU_SUBMENU (lbl, items) /* multi line expression */
Define a submenu item.
define SYN_MENU_TOGGLE (lbl, ptr) /* multi line expression */
Define a boolean toggle item.
define SYN_MENU_VALUE (lbl, ptr, mn, mx, st) /* multi line expression */
Define a numeric value editor item.

Detailed Description

Static, data-driven menus for CLI or display. No dynamic allocation. Navigation via up/down/enter/back. Supports submenus, callbacks, toggles, and integer values with min/max/step.

Usage:

static bool led_on = false;
static int32_t brightness = 50;

static const SYN_MenuItem settings_items[] = {
    SYN_MENU_TOGGLE("LED", &led_on),
    SYN_MENU_VALUE("Brightness", &brightness, 0, 100, 5),
    SYN_MENU_CALLBACK("Save", save_settings, NULL),
};

static const SYN_MenuItem root_items[] = {
    SYN_MENU_SUBMENU("Settings", settings_items),
    SYN_MENU_CALLBACK("Reboot", do_reboot, NULL),
};

SYN_MENU_ROOT(root, root_items);

static SYN_Menu menu;
syn_menu_init(&menu, &root, my_render, NULL);

Public Types Documentation

enum SYN_MenuAction

Menu item action types.

enum SYN_MenuAction {
    SYN_MENU_ACTION_SUBMENU = 0,
    SYN_MENU_ACTION_CALLBACK = 1,
    SYN_MENU_ACTION_TOGGLE = 2,
    SYN_MENU_ACTION_VALUE = 3
};


typedef SYN_MenuRenderFn

Menu render callback — called after each navigation change.

typedef void(* SYN_MenuRenderFn) (const struct SYN_Menu *menu, void *ctx);

Parameters:

  • menu Menu state.
  • ctx User context.

Public Functions Documentation

function syn_menu_back

Back: leave submenu or exit edit mode.

void syn_menu_back (
    SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

function syn_menu_down

Move selection down. In edit mode: decrement value.

void syn_menu_down (
    SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

function syn_menu_enter

Enter: navigate into submenu, toggle, start editing, or fire callback.

void syn_menu_enter (
    SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

function syn_menu_init

Initialize menu system.

void syn_menu_init (
    SYN_Menu * menu,
    const SYN_MenuItem * root,
    SYN_MenuRenderFn render,
    void * ctx
) 

Parameters:

  • menu Menu state.
  • root Root menu item (should be a SUBMENU).
  • render Render callback (called after each navigation action).
  • ctx Context for render callback.

function syn_menu_render

Force a render (e.g. after external state change).

void syn_menu_render (
    const SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

function syn_menu_up

Move selection up. In edit mode: increment value.

void syn_menu_up (
    SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

Public Static Functions Documentation

function syn_menu_item_count

Get the number of items in the current menu level.

static inline uint8_t syn_menu_item_count (
    const SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

Returns:

Item count.


function syn_menu_selected_item

Get the currently selected item.

static inline const SYN_MenuItem * syn_menu_selected_item (
    const SYN_Menu * menu
) 

Parameters:

  • menu Menu state.

Returns:

Pointer to the selected menu item.


Macro Definition Documentation

define SYN_MENU_CALLBACK

Define a callback action item.

#define SYN_MENU_CALLBACK (
    lbl,
    fn,
    c
) `/* multi line expression */`


define SYN_MENU_MAX_DEPTH

#define SYN_MENU_MAX_DEPTH `8`

Max nesting depth (stack size)


define SYN_MENU_ROOT

Define the root menu.

#define SYN_MENU_ROOT (
    name,
    items
) `static const SYN_MenuItem name = SYN_MENU_SUBMENU (#name, items)`


define SYN_MENU_SUBMENU

Define a submenu item.

#define SYN_MENU_SUBMENU (
    lbl,
    items
) `/* multi line expression */`


define SYN_MENU_TOGGLE

Define a boolean toggle item.

#define SYN_MENU_TOGGLE (
    lbl,
    ptr
) `/* multi line expression */`


define SYN_MENU_VALUE

Define a numeric value editor item.

#define SYN_MENU_VALUE (
    lbl,
    ptr,
    mn,
    mx,
    st
) `/* multi line expression */`



The documentation for this class was generated from the following file src/syntropic/ui/syn_menu.h