CUI

Components / Inputs

Text field

A single-line field that edits text in a buffer you own, with a label, an icon, a hint and an error. The search field is a variant.

Functions: cui_input, cui_search

Text field

Usage

static char email[128];
int r = cui_input(ui, "email", email, sizeof email, .label = "Email", .icon = CUI_ICON_MAIL,
                  .placeholder = "you@company.com", .hint = "Used to sign in and for receipts.");
if (r & CUI_CHANGED) validate();
if (r & CUI_SUBMITTED) submit();          /* Enter */

cui_input(ui, "password", pw, sizeof pw, .label = "Password", .password = true,
          .error = strlen(pw) < 8 ? "Use 8 or more characters." : NULL);
cui_search(ui, "q", query, sizeof query, .placeholder = "Search projects");

You own the buffer; CUI never writes past cap. Returns flags: CUI_CHANGED, CUI_SUBMITTED, CUI_FOCUSED, CUI_BLURRED.

Option
label, placeholder, hint, error
iconLeading icon
passwordMasks the text and adds a show/hide button
clearableAdds a clear button when not empty (always on for cui_search). Hidden for read_only fields; Ctrl+Z restores the cleared text
autofocus, read_only, disabled, size, width

Editing: click to place the caret, drag or Shift+arrows to select, double click selects a word, triple click selects everything. Ctrl (Option on macOS) with arrows or Backspace moves or deletes by word. Home/End, Ctrl+A, cut, copy, paste, undo and redo (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y; Cmd on macOS). Esc clears the selection, then leaves the field. Full UTF-8.

Keyboard

  • Editing: click to place the caret, drag or Shift+arrows to select, double click selects a word, triple click selects everything.
  • Ctrl (Option on macOS) with arrows or Backspace moves or deletes by word.
  • Home/End, Ctrl+A, cut, copy, paste, undo and redo (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y; Cmd on macOS).
  • Esc clears the selection, then leaves the field.

Options of cui_input, cui_search

OptionTypeDefaultDescription
.labelconst char *label above the field
.placeholderconst char *Muted text shown while the field is empty.
.iconconst char *leading icon
.hintconst char *helper text below
.errorconst char *error text below (red)
.passwordboolshows dots instead of the text, with an eye button that reveals it
.disabledboolGreyed out, and takes no input.
.clearableboolx button when not empty
.autofocusboolTakes the keyboard focus when it first appears.
.read_onlyboolShows the value but does not let it be edited.
.sizecui_control_sizeOne of CUI_SIZE_MD, CUI_SIZE_SM or CUI_SIZE_LG.
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.heightfloattextarea: height in points; negative fills the space
.prefixconst char *muted text before the value, e.g. "$" or "https://"
.suffixconst char *muted text after the value, e.g. "USD" or "kg"

Related

  • Text area: A multi-line text field that wraps and scrolls.
  • Number field: A field for a number in a range, typed or stepped with its buttons and the arrow keys.
  • Tag input: A field that turns typed words into removable chips, kept as a comma separated list.
  • One time code: A row of boxes for a verification code, filled by typing or pasting.