GGUI/Public/UIActions.h file

Input actions: what a key does, separate from which key does it.

A shortcut is never display text. It is a chord (key + modifiers) bound to an action, and an action has a name, a title, and a default chord the user can change. It has a second chord, the alternate, so a person can add their own without losing the default.

inline constexpr GGInputAction OpenScene{ "Editor.Scene.Open", "Open Scene", "Open a scene file",
                                          GGChord::Ctrl(GGKeys::O) };

ui.Command(OpenScene, [] { Open(); });      // handler, active while focus is inside this element
ui.MenuItem(OpenScene);                     // shows the title and current chord; runs the command
ui.Command(GGChord::Alt(GGKeys::F4), [] { Quit(); });   // fixed chord, not rebindable

Names are dotted tags, widest scope first ("Editor.Viewport.Frame"). Everything before the last dot is the category. Two actions only conflict over a chord if one category contains the other, so "Editor.Viewport" and "Editor.Outliner" can reuse the same chord.

Keys are USB HID keyboard usages, which every platform already reports. Key names are localised as Key.<number> (modifiers: "Key.Ctrl", "Key.Shift", "Key.Alt"), with an English fallback. Action titles and tooltips are localised wherever they are shown.

The UI's own navigation keys are actions too (GGNav) and can be rebound. While a text field has focus, the physical keys keep their normal meaning.

An action can also have a gamepad button, named by where it is (GGPad), shown by prompts when the player is using a gamepad:

inline constexpr GGInputAction Buy{ "Game.Buy", "Game.Action.Buy", "Game.Action.Buy.Tip", GGChord(GGKeys::E), {}, GGPad::South };

Non-default bindings are saved as hand-editable text, one per line, keys by name:

Editor.Scene.Open = Ctrl+Shift+O
Editor.Edit.Redo = Ctrl+Y, Ctrl+Shift+Z      (primary, alternate)
Editor.Viewport.Frame = None
Game.Buy = E | Pad.North                     (a gamepad button after a bar)

An action missing from the file keeps its default. ui.KeyBinding(action) is the rebinding control for a settings page.

Namespaces

namespace GGUI
namespace GGUI::GGKeys
The keys, by name: letters, digits (D0 to D9), the function keys, editing and arrow keys, and the number pad (Num0 to Num9, NumEnter...).
namespace GGUI::GGNav
The UI's own keys as rebindable actions, e.g. ui.KeyBinding(GGNav::Accept).

Classes

struct GGUI::GGChord
A key plus modifiers (UIMods).
struct GGUI::GGInputAction
Something a key or gamepad button does: its name, title, and default bindings. Declared as a constant; the strings must outlive every use.
class GGUI::GGActionMap
GGActionMap: registered actions and their current chords.
struct GGUI::GGActionMap::Entry
A registered action and its bindings.
struct GGUI::KeyBindingProps
Properties of ui.KeyBinding, which shows an action's chord and rebinds it.
struct GGUI::CommandEvent
A command running (ui.Command).