Overview
TheRenderable class is the foundation for all UI components in OpenTUI. It provides layout management using Yoga (Flexbox), event handling, lifecycle management, and rendering capabilities.
Base Classes
BaseRenderable
The most basic renderable interface.Unique identifier for the renderable
Internal numeric identifier (auto-assigned)
Whether the renderable is visible
Parent renderable (null for root)
Renderable
ExtendsBaseRenderable with full layout, styling, and event support.
Constructor
The renderer context (usually
renderer)Configuration options
Options
RenderableOptions
Configuration interface for creating renderables.Layout Properties
Width in cells, auto, or percentage
Height in cells, auto, or percentage
Flex grow factor (Flexbox)
Flex shrink factor (Flexbox)
Flex basis (Flexbox)
Flex direction (Flexbox)
Flex wrap (Flexbox)
Align items (Flexbox)
justifyContent
'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly'
Justify content (Flexbox)
Align self (Flexbox)
Position type
Overflow behavior
Top position (for absolute positioning)
Right position
Bottom position
Left position
Minimum width
Minimum height
Maximum width
Maximum height
Margin on all sides
Horizontal margin (left and right)
Vertical margin (top and bottom)
Top margin
Right margin
Bottom margin
Left margin
Padding on all sides
Horizontal padding
Vertical padding
Top padding
Right padding
Bottom padding
Left padding
Visual Properties
Z-index for layering (higher values render on top)
Whether the element is visible
Opacity (0 = transparent, 1 = opaque)
Behavior Properties
Use a frame buffer for rendering (performance optimization)
Keep the renderer running continuously
Hooks
Called before rendering this element
Called after rendering this element
Event Handlers
General mouse event handler (all mouse events)
Mouse button down event
Mouse button up event
Mouse move event
Mouse drag event
Mouse drag end event
Mouse drop event
Mouse over event (hover)
Mouse out event (leave)
Mouse scroll event
Key down event (when focused)
Paste event (when focused)
Called when the element’s size changes
Properties
Position and Size
Absolute x position in the terminal
Absolute y position in the terminal
Computed width in cells
Computed height in cells
X translation offset
Y translation offset
State
Visibility state (can be set to show/hide)
Opacity value (0-1)
Z-index for rendering order
Whether the element can receive keyboard focus
Whether the element currently has focus
Whether the element keeps the renderer running
Whether the element has been destroyed
Context
The renderer context
Methods
Hierarchy Management
add()
Add a child element.Child element to add
Optional index to insert at
Index where the child was inserted (-1 if failed)
remove()
Remove a child element by ID.ID of the child to remove
insertBefore()
Insert a child before another child.Element to insert
Anchor element to insert before
Index where the element was inserted
getChildren()
Get all children.Array of child elements
getChildrenCount()
Get the number of children.Number of children
getRenderable()
Get a child by ID.Child ID
The child element or undefined
findDescendantById()
Recursively find a descendant by ID.Descendant ID
The descendant or undefined
Focus Management
focus()
Give keyboard focus to this element.blur()
Remove keyboard focus from this element.Rendering
requestRender()
Request a re-render.Lifecycle
destroy()
Destroy this element and remove it from the hierarchy.destroyRecursively()
Destroy this element and all descendants.Layout
getLayoutNode()
Get the Yoga layout node.The Yoga layout node
Overridable Methods
These methods can be overridden in subclasses to customize behavior.renderSelf()
Render the element itself (called during render pass).Buffer to render to
Time since last render (in milliseconds)
onUpdate()
Called before rendering (for animations, state updates, etc.).Time since last update
onResize()
Called when the element is resized.New width
New height
onRemove()
Called when the element is removed from its parent.destroySelf()
Called during destruction (for cleanup).onMouseEvent()
Called for mouse events (after event handlers).The mouse event
handleKeyPress()
Called for key press events (when focused).The key event
Whether the event was handled
handlePaste()
Called for paste events (when focused).The paste event