CUI

Components / Actions

Button

Starts an action when clicked. It comes in six variants and three sizes, with an optional icon and a loading state.

Functions: cui_button

Button

Usage

if (cui_button(ui, "Save", .variant = CUI_BUTTON_PRIMARY, .icon = CUI_ICON_CHECK)) save();
cui_button(ui, "Cancel");
cui_button(ui, "Saving", .variant = CUI_BUTTON_PRIMARY, .loading = true);
OptionValues
variantCUI_BUTTON_SECONDARY (default), PRIMARY, OUTLINE, GHOST, DANGER, LINK
sizeCUI_SIZE_SM (30), CUI_SIZE_MD (36, default), CUI_SIZE_LG (44)
icon, icon_rightAny CUI_ICON_*
loadingShows a spinner, ignores clicks, keeps the label so nothing jumps
disabled, selected, full_width, width
colorText and icon color. Pair it with selected for toggles: .selected = liked, .color = liked ? CUI_COLOR_ACCENT : CUI_TRANSPARENT
tooltip, shortcutTooltip text and a shortcut hint

Use one primary button per view. Presses scale to 0.97 on a snappy spring. Keyboard: Tab to focus, Enter or Space to press.

Every state, rendered by tests/component_shots.c. The focus ring only appears for keyboard focus, never after a click.

Keyboard

  • Tab to focus, Enter or Space to press.

Options of cui_button

OptionTypeDefaultDescription
.variantcui_button_variantOne of CUI_BUTTON_DEFAULT, CUI_BUTTON_SECONDARY, CUI_BUTTON_PRIMARY, CUI_BUTTON_OUTLINE, CUI_BUTTON_GHOST, CUI_BUTTON_DANGER or CUI_BUTTON_LINK.
.sizecui_control_sizeOne of CUI_SIZE_MD, CUI_SIZE_SM or CUI_SIZE_LG.
.iconconst char *leading icon, e.g. CUI_ICON_PLUS
.icon_rightconst char *trailing icon
.disabledboolGreyed out, and takes no input.
.loadingboolspinner, ignores clicks
.full_widthboolStretches to the width of its container.
.selectedbooltoggled look
.tooltipconst char *Text shown when the pointer rests on it.
.shortcutconst char *shown as a hint in the tooltip, e.g. "Ctrl S"
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.colorcui_colortext and icon color, e.g. CUI_COLOR_ACCENT for a toggled icon

Related

  • Icon button: A round button with only an icon, ghost by default.
  • Button group, copy and hold to confirm: Three small helpers for actions: buttons joined into one group, a button that copies text to the clipboard, and a button that must be held to fire.
  • Split button: A main action with a menu of related actions behind a chevron.
  • Toggle group: A row of joined toggle buttons, each on or off, or exactly one on at a time.