CUI

Components / Inputs

Shortcut recorder

A field that records a key combination, for settings where people choose their own shortcuts.

Functions: cui_key_name, cui_shortcut, cui_shortcut_label, cui_shortcut_recorder

Shortcut recorder

Usage

static cui_key_combo palette_key = { CUI_MOD_PRIMARY, CUI_KEY_K };
if (cui_shortcut_recorder(ui, "palette-key", &palette_key)) save_keymap();
if (cui_shortcut(ui, palette_key.mods, palette_key.key)) open_palette();

Click and press a combination. While recording, the field shows the modifiers you hold with a pulsing dot, and app shortcuts stay quiet. Backspace clears, Esc or Tab cancels. cui_shortcut_label(ui, combo) gives the text ("Ctrl Shift K"), cui_key_name(key) one key.

cui_shortcut_recorder returns true on the frame the combination changes: a new one was recorded, or it was cleared. palette_key is your cui_key_combo, a mods mask of CUI_MOD_* bits and a key, and the recorder writes both. A key of CUI_KEY_NONE means no shortcut, and the field then shows placeholder ("Click to record"). cui_shortcut returns true on the frame the key goes down with exactly those modifiers. cui_shortcut_label returns text that lives for the current frame only, so copy it to keep it.

Keyboard

  • Backspace clears, Esc or Tab cancels.
  • cui_shortcut_label(ui, combo) gives the text ("Ctrl Shift K"), cui_key_name(key) one key.
  • Tab focuses the field, and Enter or Space starts recording. While recording, Backspace or Delete clears the shortcut, and Esc or Tab cancels.

Options of cui_shortcut_recorder

OptionTypeDefaultDescription
.placeholderconst char *Muted text shown while the field is empty.
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.

Related

  • Dropzone: An area that takes files dropped from the desktop, and can open the system file dialog on a click.
  • Prefix and suffix: Fixed text before or after a field's value, such as https:// or a unit.
  • Avatar upload: A profile picture you replace by dropping an image on it.
  • Money field: A field for an amount of money, with a currency symbol and grouped digits.