Back to Projects
TUIX v0.2.1Beta

Last Updated: 2026-05-20

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.contents

API Functions

tuix_input_set_placeholder(obj, text)

Sets the placeholder text displayed when the input is empty.

ParameterTypeDescription
objTuixObjectObject pointer
textbytesPlaceholder text (e.g. b"Type your name...")
objects.tuix_input_set_placeholder(obj, b"Enter your name...")

tuix_input_feed_input(obj, snapshot)

Processes an input snapshot. Supports character typing, Backspace, Delete, Left/Right arrow cursor movement, Home/End, and Enter to submit.

ParameterTypeDescription
objTuixObjectObject pointer
snapshotTuixInputSnapshotInput snapshot from input.get_snapshot()

tuix_input_is_submitted(obj)

Returns whether the user has submitted the input by pressing Enter.

ReturnsDescription
boolTrue 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.

ReturnsDescription
str/bytesCurrent text content

tuix_input_get_result(obj)

Returns the submitted text. Only valid after is_submitted returns True.

ReturnsDescription
str/bytes | NoneSubmitted 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

KeyAction
Any printable characterInsert at cursor position
BackspaceDelete character before cursor
DeleteDelete character at cursor position
Left ArrowMove cursor left
Right ArrowMove cursor right
HomeMove cursor to beginning
EndMove cursor to end
EnterSubmit 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...")

while True:
    snap = input.get_snapshot()
    objects.tuix_input_feed_input(obj, snap)
    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()