This page provides a comprehensive overview of Basalt2's built-in UI components, their organization, inheritance hierarchy, and instantiation patterns. UI components are visual and interactive elements that make up the user interface of a Basalt application.
For detailed information about specific component categories, see:
For information about the base element classes and rendering system, see Element Hierarchy.
All UI components in Basalt2 inherit from a base class hierarchy that provides progressively more specialized functionality. This inheritance structure enables code reuse and maintains separation of concerns.
Sources: config.lua105-444 BasaltLS.lua1-2500 Diagram 2 from high-level architecture
| Class | Primary Responsibility | Key Features |
|---|---|---|
BaseElement | Property system and events | Property definitions, observers, event registration, state management |
VisualElement | Rendering and positioning | x, y, z, width, height, background, foreground, constraints, render buffer interaction |
Container | Child management | children array, event propagation, z-index sorting, focus management, offset management |
BaseFrame | Terminal integration | Terminal binding, peripheral support, event dispatch root, top-level rendering |
Sources: elements/BaseElement.lua1-500 elements/VisualElement.lua1-1000 elements/Container.lua1-800 elements/BaseFrame.lua1-300
Components are organized into functional categories based on their primary purpose. Each category is defined in the component registry and can be loaded on demand.
Sources: config.lua105-444
All components are registered in config.lua with metadata including dependencies, file paths, and default loading status.
| Property | Description |
|---|---|
path | Relative path to component file within elements/ directory |
requires | Array of parent class names that must be loaded first |
description | Human-readable description of component functionality |
default | Boolean indicating if component is included in default release build |
size | File size in bytes |
Example registry entry:
Sources: config.lua276-284
Components are instantiated through the elementManager which handles dependency resolution, caching, and class creation.
Sources: elementManager.lua1-500 elements/Button.lua227-229
The Container class provides convenience methods for creating child elements. Each method corresponds to a registered component type.
Method naming pattern: add<ComponentName>(props)
Example methods:
container:addButton(props) → Creates Button instancecontainer:addLabel(props) → Creates Label instancecontainer:addFrame(props) → Creates Frame instanceThese methods are automatically generated by the system and handle:
elementManager.getElement()Component.new()addChild()Sources: elements/Container.lua1-900
Components can also be instantiated manually without a parent container:
Sources: elementManager.lua200-300
All UI components share common patterns inherited from their base classes.
Components use the property system defined in BaseElement for reactive state management.
Property definition:
This automatically generates:
get<PropertyName>() methodset<PropertyName>(value) methodSources: propertySystem.lua1-500 elements/BaseElement.lua1-400
Components define events using defineEvent() which creates:
on<EventName>(callback)fireEvent(eventName, ...args)observe(eventName, callback)Common events:
mouse_click - Mouse button pressedmouse_up - Mouse button releasedmouse_drag - Mouse moved while button heldmouse_scroll - Mouse wheel scrolledmouse_move - Mouse position changedkey - Keyboard key pressedkey_up - Keyboard key releasedchar - Character typedSources: elements/BaseElement.lua200-400 elements/VisualElement.lua500-1000
All visual components implement the render() method which writes to the parent's render buffer:
Rendering methods:
blit(x, y, text, fg, bg) - Write text with colorstextFg(x, y, text, color) - Write text with foreground colortextBg(x, y, text, color) - Write text with background colormultiBlit(x, y, width, height, text, fg, bg) - Write repeated patternSources: elements/VisualElement.lua800-1200 render.lua1-200
Components support multiple visual states that can be set and unset dynamically:
| State | Description |
|---|---|
focused | Element has keyboard focus |
hovered | Mouse is over element |
pressed | Mouse button is held down on element |
disabled | Element is non-interactive |
State methods:
setState(stateName) - Add stateunsetState(stateName) - Remove statehasState(stateName) - Check if state is activegetResolved(propertyName) - Get property value for current stateSources: elements/BaseElement.lua300-500
The elementManager handles component loading with automatic dependency resolution.
Sources: elementManager.lua1-500 config.lua105-444
| Component | Direct Dependency | Transitive Dependencies |
|---|---|---|
Button | VisualElement | BaseElement |
Frame | Container | VisualElement, BaseElement |
Dialog | Frame | Container, VisualElement, BaseElement |
ComboBox | DropDown | List, Collection, VisualElement, BaseElement |
Table | Collection | VisualElement, BaseElement |
Sources: config.lua276-444
The elementManager supports loading components from remote URLs or disk mounts when they are not available locally.
Configuration:
elementManager.setDiskMount(path) - Set path for disk-based loadingSources: elementManager.lua300-500
Components in the registry have a default flag indicating whether they are included in the standard release build.
Always included:
Excluded by default (must be explicitly loaded):
TextBox - Large file with syntax highlighting and autocompleteComboBox - Combines dropdown with editable inputDropDown - Dropdown selection menuDisplay - CC Window API wrapperImage - BIMG format image displayBigFont - Large text renderingLineChart, BarChart - Charting componentsGraph - Point-based graph visualizationSources: config.lua105-444
The following table summarizes common properties available across all visual components:
| Property Category | Properties | Inherited From |
|---|---|---|
| Positioning | x, y, z | VisualElement |
| Sizing | width, height | VisualElement |
| Styling | background, foreground | VisualElement |
| Visibility | visible, transparent | VisualElement |
| Interactivity | enabled, focusable | VisualElement |
| Container | children, offsetX, offsetY | Container |
| State | State-specific variants of style properties | BaseElement |
State-specific properties:
hoverBackground, hoverForegroundpressedBackground, pressedForegrounddisabledBackground, disabledForegroundfocusedBackground, focusedForegroundSources: elements/VisualElement.lua1-500 elements/Container.lua1-300
Basalt2 provides a comprehensive component library organized into a clean inheritance hierarchy. Components are:
config.lua with metadata and dependencieselementManager with automatic dependency resolutionadd<Component>() methods or manuallyFor detailed information about specific components, refer to the category-specific pages listed at the top of this document.
Sources: config.lua1-510 elementManager.lua1-500 elements/BaseElement.lua1-500 elements/VisualElement.lua1-1000 elements/Container.lua1-900
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.