Overview
Renderables are the fundamental building blocks of OpenTUI interfaces. EachRenderable is:
- A visual element (text, box, input field, etc.)
- Positioned using Yoga flexbox layout
- Part of a hierarchical tree structure
- Capable of handling mouse and keyboard events
- Independently styled and configurable
Creating Renderables
Renderables are created by instantiating their class with a renderer context:Every renderable requires a
RenderContext (the renderer) as its first argument.Renderable Hierarchy
Parent-Child Relationships
Renderables form a tree structure usingadd() and remove():
Tree Navigation
Insertion & Removal
Positioning & Sizing
Dimensions
Renderables support fixed, auto, and percentage-based sizing:Position Types
Renderables can be positioned relatively (in flexbox flow) or absolutely:Edge Offsets
Coordinates
Renderables track both local and absolute positions:Styling
Visibility
Opacity
Z-Index
Control rendering order (higher values render on top):Overflow
Control how content beyond bounds is handled:Rendering
Custom Rendering
Renderables can define custom rendering logic:Render Hooks
Add logic before or after rendering:Buffered Rendering
Enable double-buffering for complex renderables:Live Renderables
Mark renderables that need continuous updates:live: true, it keeps the render loop active even when nothing changes.
Events
Mouse Events
Focus Events
Focusable renderables receive keyboard input:Layout Events
Size Change Callback
Lifecycle
Update Cycle
Each frame, renderables go through:- onUpdate(deltaTime) - Update state
- updateFromLayout() - Apply layout calculations
- renderSelf(buffer, deltaTime) - Draw to buffer