Text input#
CEUI has a one line text field, ui_input, and a multi-line text area, ui_textarea. Both edit a zero-terminated
char buffer of yours in place.
Text fields#
static char name[17];
if (ui_input("Name", name, sizeof name, UI_INPUT_UPPER)) submit(name);
size is the size of the whole buffer, terminator included, so name above holds up to 16 characters. When the
buffer is full, further characters are ignored; nothing is ever written past size. The buffer must hold a valid
string before the first frame; a static or zeroed buffer is an empty string.
ui_input returns true when the user presses [enter] in the field, and focus then moves to the next widget. That
makes a form easy to fill from top to bottom.
The label is drawn on the left like other labeled controls. Pass NULL for a field the full width of its column.
Flags#
Flag |
Effect |
|---|---|
|
Starts in lower case mode |
|
Starts in upper case mode |
|
Starts in number mode and stays there; |
|
Draws a |
Combine them with |, for example UI_INPUT_NUMERIC | UI_INPUT_SECRET for a PIN.
Modes#
A field has three modes. [alpha] cycles through them, and the focused field shows the mode letter at its right end.
Mode |
Shown as |
Keys type |
|---|---|---|
Upper case |
|
The green letter printed above each key, in upper case |
Lower case |
|
The same letters in lower case |
Numbers |
|
The digit or symbol printed on the key |
Only the focused field has a cursor and a mode. When focus enters a field, the cursor goes to the end of the text and the mode goes back to the one its flags start in.
A, then [alpha] and b, then [alpha] again and 12. The field shows mode 1 on the right.#
Keys#
Key |
Effect |
|---|---|
Letter keys |
Type a character from the key map below |
|
Move the cursor. A text field keeps both arrows, so they never move focus |
|
Delete the character before the cursor. It repeats while held |
|
Empty the field. On an empty field the key goes on to your program |
|
Leave the field |
|
Submit: |
|
Next mode |
Key map#
In A and a modes:
Key |
Types |
Key |
Types |
Key |
Types |
|---|---|---|---|---|---|
|
A |
|
B |
|
C |
|
D |
|
E |
|
F |
|
G |
|
H |
|
I |
|
J |
|
K |
|
L |
|
M |
|
N |
|
O |
|
P |
|
Q |
|
R |
|
S |
|
T |
|
U |
|
V |
|
W |
|
X |
|
Y |
|
Z |
|
space |
|
|
|
|
|
|
[3], which has θ above it, types nothing.
In 1 mode, keys type 0 to 9, ., (, ), ,, +, -, *, / and ^, and [(-)] types -.
What is shown#
The field scrolls its text sideways so the cursor stays visible. It shows at most 80 characters around the cursor; longer buffers are still edited correctly.
A secret field, with a caption shown only while it has focus.#
Text areas#
static char notes[400];
static ui_scroll_t notes_scroll;
ui_textarea(notes, sizeof notes, ¬es_scroll, 72);
ui_caption(ui_fmt("%u of %u characters", (unsigned)strlen(notes), (unsigned)(sizeof notes - 1)));
The same editor over several wrapped lines, in a box h pixels high with its own scroll bar. It returns true in the
frame the text changed.
The differences from a text field:
[enter]inserts a line break.[up]and[down]move the cursor between lines, keeping its horizontal position. They leave the area at the first and the last line.[clear]empties the whole text.It starts in lower case mode, and
[alpha]cycles the modes as in a text field.The
ui_scroll_tholds how far the area is scrolled. Keep it with the buffer. The area scrolls to keep the cursor visible.
A text area lays out at most 64 lines.
Text in the notes area, with a line break typed with [enter].#
A complete form#
static struct {
char name[17], password[17];
int age;
bool problem_open;
} form = {.age = 16};
ui_scroll_begin(&scroll, UI_FILL);
ui_input("Name", form.name, sizeof form.name, UI_INPUT_UPPER);
ui_input("Password", form.password, sizeof form.password, UI_INPUT_SECRET);
ui_number("Age", &form.age, 5, 120);
if (ui_button("Create")) form.problem_open = strlen(form.password) < 4;
ui_scroll_end();
ui_message(&form.problem_open, "Check the form", "The password needs at least 4 characters.");
The Forms screen of the showcase, starting on the name field in upper case mode.#