CUI

Components / Inputs

Money field

A field for an amount of money, with a currency symbol and grouped digits.

Functions: cui_money_input

Usage

static double amount = 1249.5;
cui_money_input(ui, "amount", &amount, .label = "Amount", .code = "USD");                       /* $ 1,249.50  USD */
cui_money_input(ui, "salary", &salary, .symbol = "\xe2\x82\xac", .code = "EUR", .decimals = -1); /* whole euros */

Shows grouped digits at rest and plain digits while you type, keeps at most decimals places (2; -1 for none) and ignores anything that is not a number. Options: label, symbol ("$"), code, decimals, width, hint.

Returns true on a frame the value changes, which while typing is every keystroke that alters the number. amount is your double in whole units of the currency. The field reads it while not focused, so a value set from code shows at once, and on leaving the field it rounds the value to decimals places and writes it back. Typing takes digits and one decimal point, and a comma counts as the point; a minus sign cannot be typed.

Keyboard

  • It edits like a text field. Left, Right, Home and End move the caret, and Backspace and Delete remove digits.

Options of cui_money_input

OptionTypeDefaultDescription
.labelconst char *A label shown above or beside the control.
.symbolconst char *"$"currency symbol before the amount, default "$"
.codeconst char *currency code after the amount, e.g. "USD"
.decimalsintDigits after the decimal point.
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.hintconst char *helper text below the field

Related

  • Prefix and suffix: Fixed text before or after a field's value, such as https:// or a unit.
  • Scrub field: A number you change by dragging sideways on it, as in design and 3D tools.
  • Shortcut recorder: A field that records a key combination, for settings where people choose their own shortcuts.
  • Inline edit: Text that turns into a field when clicked, for renaming things in place.