Skip to content

UXMenuItem

UXMenuItem is one entry of a UXMenu: the title, the enabled and checked state, isSeparator, and the callback action a selection fires (auto-zeroing). addItem makes them. Change live state through the bar’s setChecked / setEnabled so the platform menu stays in step; the fields only describe the state at install time.

From 0.7 an item can have a shortcut:

edit.addItem((u8*)"Undo", &self.onUndo).setShortcut((u8)'Z', false);
edit.addItem((u8*)"Redo", &self.onRedo).setShortcut((u8)'Z', true); // with Shift

The key is pressed with the platform’s command key: Command on macOS and iOS, Control elsewhere. Each backend shows the shortcut the way its own menus do and fires the item when it is pressed:

backendshown ashandled by
AppKit⌘Z, ⇧⌘Zthe menu’s key equivalent
GTKCtrl+Za shortcut controller on each window
Win32Ctrl+Z, right-alignedUXMenuBar.performShortcut
web⌘Z on a Mac, Ctrl+Z elsewherethe page
GEM^Z in the item’s textUXMenuBar.performShortcut
iOS, Androidnot shownnot handled
void setAction(callback a void(UXMenuItem* sender))

The callback a selection fires. A callback never owns its controller. The handler receives the item, so one method can serve several entries.

UXMenuItem* setShortcut(u8 k, bool shift)

Gives the item a shortcut: the command key with k, and Shift as well when shift. A letter is stored in upper case. Returns the item, so it can follow addItem on the same line. Set it before the bar is installed.

void fire(void)

Calls the action if one is set. The bar’s selection decoder calls this; app code rarely does.

u8* encoded(void)

The driver form: "-" for a separator, a marker byte for pre-ticked or greyed items, then the title and, after a tab, the shortcut ("Undo\tZ", "Redo\t+Z"). UXMenuKey reads it back. Driver plumbing.