Back to Projects
TUIX v0.1Alpha

Last Updated: 2026-05-20

ComponentAPI Reference

Full API reference for the ComponentAPI class, accessible via engine.components.

create(type, id, classes=[])

Registers a new component in the objects dictionary.

ParameterTypeDescription
typestrComponent type: 'choice', 'progress_bar', or 'text_input'
idstrUnique identifier for the component
classeslistReserved for future use (default: [])

Raises ValueError if the id already exists or type is unknown. The component is initialized with default layout parameters (width_modifier=0.5, height_modifier=0.5, margins=0.0, margin modes='custom') and type-specific properties set to defaults (empty string for label/default_text, empty list for choices, 0 for progress).

engine.components.create('choice', 'menu_1')
engine.components.create('progress_bar', 'loader')
engine.components.create('text_input', 'name_input')

set_property(*, id, param, value)

Sets a property on an existing component. Uses keyword-only arguments.

ParameterTypeDescription
idstrID of the target component
paramstrProperty name: 'label', 'choices', 'progress', or 'default_text'
valueanyNew value for the property

Raises ValueError if: the id doesn't exist, the param is unknown, or the param is not applicable for the component's type.

get(id)

Returns the component dictionary for the given id. Raises ValueError if the id doesn't exist.

obj = engine.components.get('menu_1')
# Returns: {'type': 'choice', 'layout': {...}, 'label': '...', 'choices': [...]}

delete(id)

Removes a component from the objects dictionary. Raises ValueError if the id doesn't exist.

engine.components.delete('menu_1')

Internal Object Structure

Each component in objects is a dictionary with the following shape:

{
    'type': 'choice',
    'layout': {
        'margin_top_mode': 'custom',
        'margin_left_mode': 'custom',
        'width_modifier': 0.5,
        'height_modifier': 0.5,
        'margin_top_modifier': 0.0,
        'margin_left_modifier': 0.0
    },
    'label': 'Select an option:',
    'choices': [
        [{'name': 'Option 1', 'action': 'action_1'}],
        [{'name': 'Option 2', 'action': 'action_2'}]
    ]
}