Skip to main content

Overview

Renderables are the fundamental building blocks of OpenTUI interfaces. Each Renderable 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 using add() and remove():

Tree Navigation

Insertion & Removal

Once destroyed, a renderable cannot be reused. Create a new instance instead.

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

Opacity affects the renderable and all its children.

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:
Buffering is useful for renderables with expensive drawing operations that don’t change every frame.

Live Renderables

Mark renderables that need continuous updates:
When a renderable is 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:
  1. onUpdate(deltaTime) - Update state
  2. updateFromLayout() - Apply layout calculations
  3. renderSelf(buffer, deltaTime) - Draw to buffer

Lifecycle Pass

Register a renderable for lifecycle callbacks:

Cleanup

Selection

Renderables can support text selection:

Properties Reference

Core Properties

Dimensions & Position

Style Properties

State Properties

Methods Reference

Tree Management

Rendering

Focus

Lifecycle