CUI

Components / Actions

Toggle group

A row of joined toggle buttons, each on or off, or exactly one on at a time.

Functions: cui_toggle_group

Toggle group

Usage

static bool format[4];          /* bold, italic, underline, code */
const char *labels[] = { "Bold", "Italic", "Underline", "Code" };
const char *icons[] = { CUI_ICON_BOLD, CUI_ICON_ITALIC, CUI_ICON_UNDERLINE, CUI_ICON_CODE };
cui_toggle_group(ui, "format", labels, 4, format, .icons = icons, .icon_only = true);

Each item flips its own bool. With .exclusive = true exactly one stays on, like a radio group. With icon_only the labels become tooltips. Arrow keys move between items.

Returns true on the frame an item is clicked. format is your array with one bool for each item: the group reads it every frame and writes the item that was clicked, or all of them when exclusive is set. Exclusive mode acts on clicks only, so start with one value already true; a click on the item that is on leaves it on. At most 32 items are shown. icon_only hides a label only where that item has an icon. For a choice held in one int, use the segmented control.

Keyboard

  • Tab, or Left and Right, move between the toggles, and Enter or Space flips the focused one.

Options of cui_toggle_group

OptionTypeDefaultDescription
.iconsconst char *const *One icon per item, in the same order as the items.
.exclusiveboolclicking an item turns it on and every other one off, like radio buttons
.icon_onlyboolitems that have an icon show only the icon, with their label as the tooltip
.sizecui_control_sizeOne of CUI_SIZE_MD, CUI_SIZE_SM or CUI_SIZE_LG.

Related

  • Segmented control: A compact set of two to five choices where one is always selected, for switching between views of the same content.
  • Confirm button: A button for destructive actions that asks for a second click before it fires.
  • Split button: A main action with a menu of related actions behind a chevron.
  • Status button: A button that shows the progress of the work it started: a spinner while busy, then a check or an error.