Back to Projects
TUIX v0.5Beta

Last Updated: 2026-05-20

Engine API

The engine module owns process-level initialization, shutdown, one-frame execution, loop stats, and mouse capture.

MethodHow to use itWhy it exists
engine.init() -> intCall once before registering builders, creating scenes, or creating objects.Initializes the native engine and registry so the C/Cython core is ready.
engine.shutdown() -> intCall during cleanup after stopping input and finishing the render loop.Releases process-level native state and registry resources.
engine.main_loop() -> NoneCall once per frame in your application loop.Runs input routing, layout, builder updates, compositing, and terminal rendering.
engine.get_core_loop_stats() -> dictRead after frames when profiling or debugging frame behavior.Exposes timing and state counters without poking native internals.
engine.mouse_capture_begin(uid: int) -> intCall when a widget starts drag/capture interaction.Keeps mouse events routed to the same UID across pointer movement.
engine.mouse_capture_end(uid: int) -> intCall when the captured drag or pointer interaction ends.Releases capture so normal hitmap/focus routing resumes.
engine.get_mouse_capture_uid() -> intUse while debugging or coordinating widgets that may capture the mouse.Reports which UID currently owns captured mouse routing.

Loop Stats Keys

get_core_loop_stats() may include frame_counter, batch_commit_ms, cache_refresh_ms, input_ms, routing_ms, buffer_ms, composite_ms, python_commit_ms, total_ms, composite_skipped, composite_forced, traversal_cache_hit, traversal_cache_miss, size_changed, has_input, has_scene, and has_subcycles.

Typical Usage

engine.init()
builders.register_standard()
scenes.init_scene('Main')
scenes.select_scene('Main')
input.listen()

while running:
    engine.main_loop()

input.stop()
engine.shutdown()