Zpět na projekty
TUIX v0.1Alfa

Naposledy aktualizováno: 2026-05-20

Reference ComponentAPI

Kompletní API reference pro třídu ComponentAPI, dostupnou přes engine.components.

create(type, id, classes=[])

Zaregistruje novou komponentu do slovníku objects.

ParametrTypPopis
typestrTyp komponenty: 'choice', 'progress_bar' nebo 'text_input'
idstrUnikátní identifikátor komponenty
classeslistRezervováno pro budoucí použití (default: [])

Vyhodí ValueError, pokud id již existuje nebo je typ neznámý. Komponenta se inicializuje s výchozími layout parametry (width_modifier=0.5, height_modifier=0.5, okraje=0.0, margin módy='custom') a vlastnosti specifické pro typ se nastaví na výchozí hodnoty (prázdný string pro label/default_text, prázdný seznam pro choices, 0 pro 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)

Nastaví vlastnost existující komponenty. Používá argumenty pouze jako keyword.

ParametrTypPopis
idstrID cílové komponenty
paramstrNázev vlastnosti: 'label', 'choices', 'progress' nebo 'default_text'
valueanyNová hodnota vlastnosti

Vyhodí ValueError, pokud: id neexistuje, parametr je neznámý nebo parametr není použitelný pro daný typ komponenty.

get(id)

Vrací slovník komponenty pro dané id. Vyhodí ValueError, pokud id neexistuje.

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

delete(id)

Odstraní komponentu ze slovníku objects. Vyhodí ValueError, pokud id neexistuje.

engine.components.delete('menu_1')

Interní struktura objektu

Každá komponenta v objects je slovník s následující strukturou:

{
    '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'}]
    ]
}