ComponentAPI
The ComponentAPI class manages the lifecycle of UI objects. Accessible via engine.components, it provides methods to create, configure, retrieve, and delete components.
Component Types
TUIX Core supports three component types:
| Type | Description | Specific Properties |
|---|---|---|
| choice | Interactive selection menu with keyboard navigation | label, choices |
| progress_bar | Visual progress indicator (0–100) | label, progress |
| text_input | Single-line text entry | label, 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
| Property | Applicable Types |
|---|---|
| label | choice, progress_bar, text_input |
| choices | choice |
| progress | progress_bar |
| default_text | text_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:
| Parameter | Default |
|---|---|
| width_modifier | 0.5 |
| height_modifier | 0.5 |
| margin_top_modifier | 0.0 |
| margin_left_modifier | 0.0 |
| margin_top_mode | custom |
| margin_left_mode | custom |