Back to Projects
TUIX v0.1Alpha

Last Updated: 2026-05-20

ComponentAPI

The ComponentAPI class manages the lifecycle of UI objects. Accessible via engine.components, it provides methods to create, configure, retrieve, and delete components.

Key ConceptComponents are stored in an internal objects dictionary keyed by unique string IDs. Each component has a type, layout parameters, and type-specific properties (label, choices, progress, default_text).

Component Types

TUIX Core supports three component types:

TypeDescriptionSpecific Properties
choiceInteractive selection menu with keyboard navigationlabel, choices
progress_barVisual progress indicator (0–100)label, progress
text_inputSingle-line text entrylabel, default_text

Creating Components

Use create(type, id) to register a new component. Raises ValueError if the ID already exists or the type is unknown.

engine.components.create('choice', 'my_menu')
engine.components.create('progress_bar', 'loader')
engine.components.create('text_input', 'name_field')

Each created component is initialized with default layout parameters: width_modifier=0.5, height_modifier=0.5, margin_top_modifier=0.0, margin_left_modifier=0.0, and both margin modes set to 'custom'.

Setting Properties

Use set_property(id, param, value) to configure a component. The method validates that the param exists and is applicable for the component's type.

# Choice menu
engine.components.set_property(id='my_menu', param='label', value='Pick one:')
engine.components.set_property(id='my_menu', param='choices', value=[
    [{'name': 'Option A', 'action': 'a'}],
    [{'name': 'Option B', 'action': 'b'}, {'name': 'Option C', 'action': 'c'}]
])

# Progress bar
engine.components.set_property(id='loader', param='progress', value=75)

# Text input
engine.components.set_property(id='name_field', param='default_text', value='John')

Property Compatibility

PropertyApplicable Types
labelchoice, progress_bar, text_input
choiceschoice
progressprogress_bar
default_texttext_input

Choices Structure

The choices property is a list of rows. Each row is a list of button dictionaries with 'name' (display text) and 'action' (identifier) keys. Buttons in the same row are rendered side by side; different rows appear on separate lines.

# Two rows: first has 2 buttons, second has 1 button
choices = [
    [{'name': 'Save', 'action': 'save'}, {'name': 'Load', 'action': 'load'}],
    [{'name': 'Quit', 'action': 'quit'}]
]

Retrieving & Deleting

Use get(id) to retrieve the component dictionary and delete(id) to remove it. Both raise ValueError if the ID does not exist.

obj = engine.components.get('my_menu')
print(obj['type'])  # 'choice'

engine.components.delete('my_menu')

Default Layout Parameters

Every component is created with the following default layout values:

ParameterDefault
width_modifier0.5
height_modifier0.5
margin_top_modifier0.0
margin_left_modifier0.0
margin_top_modecustom
margin_left_modecustom

Current Limitations

Single Component RenderingCurrently only one component can be rendered at a time, and only the choice type is fully supported for rendering. progress_bar and text_input components can be created and configured but do not yet have render implementations.
FuturePlanned: multi-component layouts, sliders, checkboxes, and additional interactive component types.