tecs.ui

Retained interfaces made from Tecs entities, with layout computed by Taffy.

Style and ChildOf describe a tree. Root supplies its available size; Paint(true) stretches a drawing leaf to its computed box. Shapes, sprites and text draw through the ordinary graphics pipeline. Keep containers at unit scale and put stretched paint on leaves. Write component fields through world:getMut so layout and rendering observe the edit.

tecs.ui.install(world, {width = 800, height = 450})
const root = world:spawn(tecs.ui.Root(), tecs.ui.Style({padding = 16, gap = 12}))
world:spawn(tecs.ecs.ChildOf(root), tecs.ui.Style({width = 120, height = 40}),
    tecs.ui.Paint(true), tecs.gfx.Tint(0.3, 0.6, 1, 1), tecs.gfx.Renderable2D,
    tecs.ui.Interaction())

Layout retains its native tree, measures intrinsic text and images without foreign callbacks, and returns changed boxes. Scrolling clips descendants; interaction supports pointer capture, dragging, focus scopes and activation. Screen roots follow resize, and plugin(app) connects window size and input.

Module contents

Types

TypeKindDescription
DimensiontypeA logical length: pixels, a percent string, or "auto".
EdgestypePer-edge logical lengths; missing edges are automatic.
EventrecordA semantic interaction delivered first to its target, then its ancestors.
InteractiontypeThe value stored by Interaction.
InteractionOptionstypeConstructor options for Interaction.
InteractionStatetypeThe value stored by InteractionState.
InteractionStateOptionstypeConstructor options for InteractionState.
IntrinsictypeThe value stored by Intrinsic.
IntrinsicOptionstypeConstructor options for Intrinsic.
LayouttypeThe value stored by Layout.
LayoutOptionstypeConstructor options for Layout.
OptionstypeSettings for layout, clipping and interaction.
PainttypeThe value stored by Paint.
RoottypeThe value stored by Root.
RootOptionstypeConstructor options for Root.
ScrolltypeThe value stored by Scroll.
ScrollbartypeThe value stored by Scrollbar.
ScrollbarOptionstypeConstructor options for Scrollbar.
ScrollOptionstypeConstructor options for Scroll.
StyletypeThe value stored by Style.
StyleOptionstypeTaffy layout properties.

Functions

FunctionKindDescription
blurfunctionClears focus and reports whether an entity was focused.
focusfunctionFocuses an enabled, focusable entity in the active scope.
focusedfunctionReturns the focused entity, or zero.
installfunctionInstalls retained layout and observes platform events; repeated installation is harmless.
layoutsfunctionReports native synchronization calls, useful for checking idle layout work.
pluginfunctionInstalls UI using the application's viewport and input.
popFocusScopefunctionPops the top scope and restores its previous focus when still valid.
pushFocusScopefunctionRestricts focus and hit testing to a subtree until popped.
resizefunctionUpdates the logical viewport used by automatic screen roots.
revealfunctionReveals a descendant by scrolling every ancestor viewport.
updatefunctionRuns layout, geometry and pending interaction for the current world state.

Values

ValueKindDescription
FocusScopevariableMarks a subtree that can own a modal focus scope.
InteractionvariableConstructs Interaction with its default values for omitted fields.
InteractionStatevariableConstructs InteractionState with its default values for omitted fields.
IntrinsicvariableConstructs Intrinsic with its default values for omitted fields.
LayoutvariableConstructs Layout with its default values for omitted fields.
NodevariableMarks a retained UI node.
PaintvariableConstructs Paint with its default values for omitted fields.
RootvariableConstructs Root with its default values for omitted fields.
ScrollvariableConstructs Scroll with its default values for omitted fields.
ScrollbarvariableConstructs Scrollbar with its default values for omitted fields.
StylevariableConstructs Style with its default values for omitted fields.

Types#

Dimensiontype#

type Dimension = number | string

A logical length: pixels, a percent string, or "auto".

Edgestype#

type Edges = {
    left: Dimension?,
    right: Dimension?,
    top: Dimension?,
    bottom: Dimension?
}

Per-edge logical lengths; missing edges are automatic.

Eventrecord#

record Event
    kind: string
    target: integer
    currentTarget: integer
    x: number
    y: number
    button: integer
    pointerId: string
    pointerType: string
    deltaX: number
    deltaY: number
    source: string
    consumed: boolean
end
@derive(nupp.events.Event)@event(name="tecs.ui.Event")

A semantic interaction delivered first to its target, then its ancestors.

Observed at an entity address, or at address zero after bubbling.

Fields

kind#
kind: string

Read-only. Identifies the interaction.

target#
target: integer

Read-only. Identifies the original target.

currentTarget#
currentTarget: integer

Read-only. Identifies the current bubbling recipient.

x#
x: number

Read-only. Reports the pointer position in target pixels.

y#
y: number

Read-only. Reports the pointer position in target pixels.

button#
button: integer

Read-only. Reports the pointer button.

pointerId#
pointerId: string

Read-only. Identifies the pointer, including a touch contact.

pointerType#
pointerType: string

Read-only. Identifies mouse, touch, or none.

deltaX#
deltaX: number

Read-only. Reports horizontal movement or wheel delta.

deltaY#
deltaY: number

Read-only. Reports vertical movement or wheel delta.

source#
source: string

Read-only. Identifies pointer, keyboard, controller, or programmatic input.

consumed#
consumed: boolean

Caller-writable. Stops bubbling when true.

Interactiontype#

type Interaction = InteractionValue

The value stored by Interaction.

InteractionOptionstype#

type InteractionOptions = {
    enabled: (boolean)?,
    focusable: (boolean)?,
    tabIndex: (integer)?,
    order: (integer)?,
    draggable: (boolean)?
}

Constructor options for Interaction.

InteractionStatetype#

type InteractionState = InteractionStateValue

The value stored by InteractionState.

InteractionStateOptionstype#

type InteractionStateOptions = {
    hovered: (boolean)?,
    pressed: (boolean)?,
    focused: (boolean)?,
    dragging: (boolean)?
}

Constructor options for InteractionState.

Intrinsictype#

type Intrinsic = IntrinsicValue

The value stored by Intrinsic.

IntrinsicOptionstype#

type IntrinsicOptions = {
    source: ("custom" | "text" | "image")?,
    width: (number)?,
    height: (number)?,
    minWidth: (number)?,
    scale: (number)?,
    wrap: (boolean)?
}

Constructor options for Intrinsic.

Layouttype#

type Layout = LayoutValue

The value stored by Layout.

LayoutOptionstype#

type LayoutOptions = {
    x: (number)?,
    y: (number)?,
    width: (number)?,
    height: (number)?,
    contentWidth: (number)?,
    contentHeight: (number)?
}

Constructor options for Layout.

Optionstype#

type Options = {
    width: number?,
    height: number?,
    pixelDensity: number?,
    firstClip: integer?,
    lastClip: integer?,
    layer: integer?,
    wheelStep: number?,
    dragThreshold: number?,
    input: Input?,
    inputLayer: Layer?
}

Settings for layout, clipping and interaction.

Painttype#

type Paint = PaintValue

The value stored by Paint.

Roottype#

type Root = RootValue

The value stored by Root.

RootOptionstype#

type RootOptions = {
    space: ("screen" | "world")?,
    width: (number)?,
    height: (number)?,
    pixelDensity: (number)?,
    sizing: ("auto" | "manual" | "camera")?
}

Constructor options for Root.

Scrolltype#

type Scroll = ScrollValue

The value stored by Scroll.

Scrollbartype#

type Scrollbar = ScrollbarValue

The value stored by Scrollbar.

ScrollbarOptionstype#

type ScrollbarOptions = {
    axis: ("horizontal" | "vertical")?,
    thickness: (number)?,
    inset: (number)?,
    minLength: (number)?
}

Constructor options for Scrollbar.

ScrollOptionstype#

type ScrollOptions = {
    x: (number)?,
    y: (number)?,
    contentWidth: (number)?,
    contentHeight: (number)?
}

Constructor options for Scroll.

Styletype#

type Style = StyleValue

The value stored by Style.

StyleOptionstype#

type StyleOptions = {
    display: ("flex" | "none" | "grid" | "block")?,
    position: ("relative" | "absolute")?,
    flexDirection: ("row" | "rowReverse" | "column" | "columnReverse")?,
    flexWrap: ("nowrap" | "wrap")?,
    justifyContent: ("start" | "center" | "end" | "spaceBetween" | "spaceAround" | "spaceEvenly")?,
    alignItems: ("stretch" | "center" | "end" | "baseline" | "start")?,
    alignContent: ("stretch" | "center" | "end" | "spaceBetween" | "spaceAround" | "spaceEvenly" | "start")?,
    flexGrow: number?,
    flexShrink: number?,
    flexBasis: Dimension?,
    width: Dimension?,
    height: Dimension?,
    minWidth: Dimension?,
    minHeight: Dimension?,
    maxWidth: Dimension?,
    maxHeight: Dimension?,
    margin: (Dimension | Edges)?,
    padding: (Dimension | Edges)?,
    border: (Dimension | Edges)?,
    gap: Dimension?,
    rowGap: Dimension?,
    inset: (Dimension | Edges)?,
    order: integer?
}

Taffy layout properties. Omitted values use Taffy's flex defaults.

Functions#

blurfunction#

function blur(exclusive world: World): boolean

Clears focus and reports whether an entity was focused.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

Returns

TypeDescription
boolean

whether focus changed

focusfunction#

function focus(exclusive world: World, entity: integer): boolean

Focuses an enabled, focusable entity in the active scope.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

entityinteger

the requested entity

Returns

TypeDescription
boolean

whether focus moved

focusedfunction#

function focused(borrows world: World): integer

Returns the focused entity, or zero.

Arguments

NameTypeDescription
borrows worldWorld

the installed world

Returns

TypeDescription
integer

the focused entity

installfunction#

function install(exclusive world: World, options: Options?): nil

Installs retained layout and observes platform events; repeated installation is harmless.

Arguments

NameTypeDescription
exclusive worldWorld

the world to install into

optionsOptions?

viewport, clip allocation and input settings

Returns

TypeDescription
nil

layoutsfunction#

function layouts(borrows world: World): integer

Reports native synchronization calls, useful for checking idle layout work.

Arguments

NameTypeDescription
borrows worldWorld

the installed world

Returns

TypeDescription
integer

the synchronization count

pluginfunction#

function plugin(exclusive app: Application, options: Options?): nil

Installs UI using the application's viewport and input.

Arguments

NameTypeDescription
exclusive appApplication

the application whose world hosts the UI

optionsOptions?

optional layout and interaction settings

Returns

TypeDescription
nil

popFocusScopefunction#

function popFocusScope(exclusive world: World, entity: integer?): boolean

Pops the top scope and restores its previous focus when still valid.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

entityinteger?

the expected scope, or nil

Returns

TypeDescription
boolean

whether a scope was popped

pushFocusScopefunction#

function pushFocusScope(exclusive world: World, entity: integer): boolean

Restricts focus and hit testing to a subtree until popped.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

entityinteger

an entity carrying FocusScope

Returns

TypeDescription
boolean

whether the scope was pushed

resizefunction#

function resize(exclusive world: World, width: number, height: number, density: number?): nil

Updates the logical viewport used by automatic screen roots.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

widthnumber

the logical viewport width

heightnumber

the logical viewport height

densitynumber?

the target pixels per logical point

Returns

TypeDescription
nil

revealfunction#

function reveal(exclusive world: World, entity: integer, align: string?): boolean

Reveals a descendant by scrolling every ancestor viewport.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

entityinteger

the descendant to reveal

alignstring?

nearest, start, center, or end; omitted means nearest

Returns

TypeDescription
boolean

whether an ancestor scrolled

updatefunction#

function update(exclusive world: World): nil

Runs layout, geometry and pending interaction for the current world state.

Arguments

NameTypeDescription
exclusive worldWorld

the installed world

Returns

TypeDescription
nil

Values#

FocusScopevariable#

Marks a subtree that can own a modal focus scope.

Interactionvariable#

const Interaction: ComponentDefinition<InteractionValue>

Constructs Interaction with its default values for omitted fields.

InteractionStatevariable#

const InteractionState: ComponentDefinition<InteractionStateValue>

Constructs InteractionState with its default values for omitted fields.

Intrinsicvariable#

const Intrinsic: ComponentDefinition<IntrinsicValue>

Constructs Intrinsic with its default values for omitted fields.

Layoutvariable#

const Layout: ComponentDefinition<LayoutValue>

Constructs Layout with its default values for omitted fields.

Nodevariable#

const Node

Marks a retained UI node. The persisted name is UiNode.

Paintvariable#

const Paint: ComponentDefinition<PaintValue>

Constructs Paint with its default values for omitted fields.

Rootvariable#

const Root: ComponentDefinition<RootValue>

Constructs Root with its default values for omitted fields.

Scrollvariable#

const Scroll: ComponentDefinition<ScrollValue>

Constructs Scroll with its default values for omitted fields.

Scrollbarvariable#

const Scrollbar: ComponentDefinition<ScrollbarValue>

Constructs Scrollbar with its default values for omitted fields.

Stylevariable#

const Style: ComponentDefinition<StyleValue>

Constructs Style with its default values for omitted fields.