TUIX v0.3Beta
Input Widget
A single-line text entry field with placeholder text, cursor movement, and submit detection.
Creating an Input Widget
from tuix.core import builders, objects, buffers
uid = objects.create_object(
builders.INPUT, b"main",
0.4, 0.1, # width: 40%, height: 10%
0.45, 0.3 # margin_top: 45%, margin_left: 30%
)
buf = buffers.get_buffer_by_uid(uid)
obj = buf.contents.obj.contentsAPI Functions
tuix_input_set_placeholder(obj, text)
Sets the placeholder text displayed when the input is empty.
| Parameter | Type | Description |
|---|---|---|
| obj | TuixObject | Object pointer |
| text | bytes | Placeholder text (e.g. b"Type your name...") |
objects.tuix_input_set_placeholder(obj, b"Enter your name...")tuix_input_feed_input(obj, snapshot)
Compatibility API: manually processes an input snapshot. Supports character typing, Backspace, Delete, Left/Right arrow cursor movement, Home/End, and Enter to submit. Standard v0.3 flows process this automatically in the frame loop.
| Parameter | Type | Description |
|---|---|---|
| obj | TuixObject | Object pointer |
| snapshot | TuixInputSnapshot | Input snapshot from input.get_snapshot() |
tuix_input_is_submitted(obj)
Returns whether the user has submitted the input by pressing Enter.
| Returns | Description |
|---|---|
| bool | True if Enter was pressed, False otherwise |
tuix_input_get_text(obj)
Returns the current text content of the input field. Never returns None — returns an empty string if no text has been entered.
| Returns | Description |
|---|---|
| str/bytes | Current text content |
tuix_input_get_result(obj)
Returns the submitted text. Only valid after is_submitted returns True.
| Returns | Description |
|---|---|
| str/bytes | None | Submitted text if Enter was pressed, None otherwise |
tuix_input_reset(obj)
Resets the widget: clears the text, resets submission state, and restores the placeholder.
Supported Keys
| Key | Action |
|---|---|
| Any printable character | Insert at cursor position |
| Backspace | Delete character before cursor |
| Delete | Delete character at cursor position |
| Left Arrow | Move cursor left |
| Right Arrow | Move cursor right |
| Home | Move cursor to beginning |
| End | Move cursor to end |
| Enter | Submit the input |
Complete Example
from tuix.core import engine, builders, scenes, registry, objects, buffers, input
engine.init()
builders.register_standard()
scenes.init_scene(b"main")
registry.registry.current_scene_name = b"main"
input.listen()
uid = objects.create_object(builders.INPUT, b"main", 0.4, 0.1, 0.45, 0.3)
buf = buffers.get_buffer_by_uid(uid)
obj = buf.contents.obj.contents
objects.tuix_input_set_placeholder(obj, b"Type your name...")
# Automatic input handling in v0.3
while True:
engine.main_loop()
if objects.tuix_input_is_submitted(obj):
break
text = objects.tuix_input_get_text(obj)
print(f"You entered: {text}")
buffers.free_buffer(b"main", uid)
scenes.free_scene(b"main")
input.stop()
engine.shutdown()