Text input
TextInput is a single-line text field. You own its state in a CC_TextEdit that lives across frames, and each call returns a bitmask of events for this frame, such as a change or Enter being pressed.
Example
static CC_TextEdit name; // zero-initialised, survives frames
static void name_field(void) {
int ev = TextInput("name", &name, .placeholder = "Your name",
.border = ColorHex(0x555555),
.borderFocused = ColorHex(0x4488FF));
if (ev & CC_TEXT_INPUT_SUBMITTED)
printf("Hello, %s\n", name.text);
}
Reference
| Name | Form | What it does | Page |
|---|---|---|---|
TextInput | int TextInput(const char *id, CC_TextEdit *edit, .field = ...) | Single-line text field. Returns a CC_TextInputEvent bitmask for this frame. Fields are CC_TextInputOpts. | Text input |
CC_TextInputOpts | struct | .sizing, .padding, .background, .border, .borderFocused, .textColor, .placeholderColor, .caretColor, .selectionColor, .cornerRadius (float), .fontId, .fontSize, .placeholder. | Text input |
CC_TextInput | int (const char *id, CC_TextEdit *edit, CC_TextInputOpts opts) | What TextInput calls. | |
CC_TextInputEvent | CC_TEXT_INPUT_CHANGED (1), CC_TEXT_INPUT_SUBMITTED (2), CC_TEXT_INPUT_FOCUSED (4), CC_TEXT_INPUT_BLURRED (8) | Bits in the TextInput return value. Test with &. | Text input |
CC_TextEdit | struct { char text[CC_TEXT_EDIT_CAP]; size_t len, cursor, max_len; bool all_selected; } | Editing state of one field. You own it, zero-initialise it, and keep it across frames. | Text input |
CC_TEXT_EDIT_CAP | 256 | Bytes in CC_TextEdit.text, including the NUL. | Text input |
CC_TextEditSet | void (CC_TextEdit *e, const char *s) | Replace the content, cursor at the end, selection cleared. | Text input |
CC_TextEditApply | bool (CC_TextEdit *e, CC_TextEditOp op, const char *text) | Apply one edit without a window, for tests or custom key handling. Returns true when the content changed. | Text input |
CC_TextEditOp | CC_EDIT_INSERT, CC_EDIT_BACKSPACE, CC_EDIT_DELETE, CC_EDIT_LEFT, CC_EDIT_RIGHT, CC_EDIT_HOME, CC_EDIT_END, CC_EDIT_SELECT_ALL | Edits CC_TextEditApply understands. | Text input |
CC_TextInputFocused | bool (const char *id) | True while that field has keyboard focus. | Text input |
CC_TextInputFocus | void (const char *id) | Give a field focus from code, for one that just appeared. | Text input |
CC_TextInputBlur | void (void) | Drop focus from whichever field has it. | Text input |