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.
Keyboard shortcuts
Section titled “Keyboard shortcuts”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 ShiftThe 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:
| backend | shown as | handled by |
|---|---|---|
| AppKit | ⌘Z, ⇧⌘Z | the menu’s key equivalent |
| GTK | Ctrl+Z | a shortcut controller on each window |
| Win32 | Ctrl+Z, right-aligned | UXMenuBar.performShortcut |
| web | ⌘Z on a Mac, Ctrl+Z elsewhere | the page |
| GEM | ^Z in the item’s text | UXMenuBar.performShortcut |
| iOS, Android | not shown | not handled |
Topics
Section titled “Topics”setAction
Section titled “setAction”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.
setShortcut
Section titled “setShortcut”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.
encoded
Section titled “encoded”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.