Docs
API Reference

UI

UI for rendering to a WebGPU canvas. Import from @uno.build/ui/UI. For engine surfaces, see UIWorldSpace.

Properties

PropertyTypeDescription
rootNode | nullRoot node.
rendererRendererWebGPU | nullRenderer instance.
resourcesResourcesWebGPU | nullResource store.
defined_eventsDefinedEvent[]Installed event definitions.
eventsEventEmitter<UIEventMap>Normalized UI events.
events_sourceEventEmitter<CoreEventMap>Source and lifecycle events.
operationsOperationsMutation journal.

Methods

MethodReturnsDescription
static create(options: UIOptions)Promise<{ ui: UI }>Creates and initializes a UI.
create()Node | undefinedCreates a detached Node.
update()voidApplies pending changes.
draw(options?: WebGPUDrawOptions)WebGPUDrawResult | undefinedDraws the current UI state.
setViewport(width: number, height: number)voidSets logical viewport dimensions.
setDevicePixelRatio(device_pixel_ratio: number)voidSets raster density.
setRootSize(root_size: number)voidSets the pixel size of 1rem.
addChild(parent: Node, child: Node, before_node: Node | null)voidInserts a child; null appends.
detachNode(node: Node)voidDetaches a subtree for reuse.
destroyNode(node: Node)voidDestroys a subtree; the root destroys the UI.
registerPlatformEvents()voidRegisters canvas event listeners.
removePlatformEvents()voidRemoves registered canvas listeners.
dispatchPlatformEvent(source_event: PlatformEvent)voidForwards a platform event into the UI.
destroy()boolean | voidDestroys the UI.

Creation options

OptionTypeDefault
resourcesResourcesWebGPURequired
register_platform_eventsbooleantrue
defined_eventsArray<(options: { ui: UI }) => DefinedEvent>[]
image_min_filter'linear' | 'nearest''linear'
image_mag_filter'linear' | 'nearest''linear'

register_platform_events registers canvas listeners during creation. UIOptions and DefinedEvent are exported by @uno.build/ui/UI. See Custom event definitions for a defined_events example.

Draw options

OptionTypeDefault
submitbooleantrue
command_encoderGPUCommandEncoderNew encoder
texture_viewGPUTextureViewCurrent canvas texture view
load_op'load' | 'clear''load'

Draw result

PropertyType
command_encoderGPUCommandEncoder
texture_viewGPUTextureView

On this page