Components / Inputs
Number field
A field for a number in a range, typed or stepped with its buttons and the arrow keys.
Functions: cui_number

Usage
static double seats = 4, price = 19.99;
cui_number(ui, "seats", &seats, 1, 100, .label = "Seats", .step = 1);
cui_number(ui, "price", &price, 0, 1e6, .decimals = 2, .suffix = "USD");
Type a value, use the minus and plus buttons, or Up/Down (Shift for 10 steps). Values are clamped to the range.
Returns true on a frame the value changes, which while typing is every keystroke that reads as a different number. seats is your double. The field shows a value you set from code as soon as it is not focused, and pulls a value outside the range back in on every frame. step is what the buttons and the keys add or take away, 1 when not set. decimals is how many places are shown, 0 when not set. It does not round the value: 2.5 typed into a field with no decimals stays 2.5 in your variable.
Keyboard
- Type a value, use the minus and plus buttons, or Up/Down (Shift for 10 steps).
Options of cui_number
| Option | Type | Default | Description |
|---|---|---|---|
.label | const char * | A label shown above or beside the control. | |
.step | double | The amount one step changes the value by. | |
.decimals | int | Digits after the decimal point. | |
.disabled | bool | Greyed out, and takes no input. | |
.width | cui_size | Width: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own. | |
.suffix | const char * | muted text after the value, before the - and + buttons, e.g. "kg" |
Related
- Tag input: A field that turns typed words into removable chips, kept as a comma separated list.
- Text area: A multi-line text field that wraps and scrolls.
- One time code: A row of boxes for a verification code, filled by typing or pasting.
- 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.