A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(ui)!: one widget contract — handles, keyboard access, and data-driven dialog/slider behavior
esengine8935a86c7a7e
diff --git a/examples/ui-controls/src/state.ts b/examples/ui-controls/src/state.tsindex 264a6f5ff..c95f43f23 100644--- a/examples/ui-controls/src/state.ts+++ b/examples/ui-controls/src/state.ts@@ -3,7 +3,6 @@ import type { SliderHandle, ProgressHandle } from 'esengine';export const state = {slider: null as SliderHandle | null,progress: null as ProgressHandle | null,- dragging: false,progressT: 0,progressDir: 1,paused: false,diff --git a/examples/ui-controls/src/systems/build.ts b/examples/ui-controls/src/systems/build.tsindex 957d119db..08d3d2ce3 100644--- a/examples/ui-controls/src/systems/build.ts+++ b/examples/ui-controls/src/systems/build.ts@@ -2,7 +2,6 @@ import {defineSystem, Res, GetWorld,UIEvents,Text, UIVisual,- Interactable, UIInteraction,spawnUIEntity,createButton, createToggle, createSlider, createProgress, createDropdown, createDialog,themeColors, px, percent,@@ -25,8 +24,11 @@ export const buildSystem = defineSystem(const c = themeColors();+ // Dialog content is built ONCE: closing sets display:none on the+ // backdrop root, which hides the whole subtree (text included) and+ // removes it from input. Escape / a scrim click also close it.const dialog = createDialog({- world, parent: canvas, startHidden: true,+ world, events, parent: canvas, startHidden: true,panelNode: {position: UIPositionType.Absolute,width: px(360), height: px(190),@@ -35,41 +37,28 @@ export const buildSystem = defineSystem(},panelVisual: { color: c.surfaceElevated },});- // Materialize the modal's content only while open — hiding a UI subtree does not hide child Text.- let dialogContent: Entity[] = [];- function closeDialog(): void {- dialog.close();- for (const e of dialogContent) if (world.valid(e)) world.despawn(e);- dialogContent = [];- }- function openDialog(): void {- if (dialogContent.length) return;- dialog.open();- dialogContent = [- spawnUIEntity({- world, parent: dialog.panelEntity,- node: { position: UIPositionType.Absolute, insetLeft: px(0), insetRight: px(0),- insetTop: px(26), height: px(26) },- text: { content: 'Hello from a modal', fontSize: 18, bold: true, color: c.onPrimary },- }),- spawnUIEntity({- world, parent: dialog.panelEntity,- node: { position: UIPositionType.Absolute, insetLeft: px(28), insetRight: px(28),- insetTop: px(66), height: px(48) },- text: { content: 'A dialog is just a backdrop plus a panel you fill with children.',- fontSize: 13, color: c.onPrimary, wordWrap: true,- verticalAlign: TextVerticalAlign.Top },- }),- createButton({- world, events, parent: dialog.panelEntity,- node: { position: UIPositionType.Absolute, width: px(120), height: px(CONTROL_H),- insetLeft: percent(50), marginLeft: px(-60), insetBottom: px(22) },- states: controlStates(c),- text: { content: 'Close', color: c.onPrimary, fontSize: 14 },- onClick: closeDialog,- }),- ];- }+ spawnUIEntity({+ world, parent: dialog.panelEntity,+ node: { position: UIPositionType.Absolute, insetLeft: px(0), insetRight: px(0),+ insetTop: px(26), height: px(26) },+ text: { content: 'Hello from a modal', fontSize: 18, bold: true, color: c.onPrimary },+ });+ spawnUIEntity({+ world, parent: dialog.panelEntity,+ node: { position: UIPositionType.Absolute, insetLeft: px(28), insetRight: px(28),+ insetTop: px(66), height: px(48) },+ text: { content: 'A dialog is just a backdrop plus a panel you fill with children.',+ fontSize: 13, color: c.onPrimary, wordWrap: true,+ verticalAlign: TextVerticalAlign.Top },+ });+ createButton({+ world, events, parent: dialog.panelEntity,+ node: { position: UIPositionType.Absolute, width: px(120), height: px(CONTROL_H),+ insetLeft: percent(50), marginLeft: px(-60), insetBottom: px(22) },+ states: controlStates(c),+ text: { content: 'Close', color: c.onPrimary, fontSize: 14 },+ onClick: () => dialog.close(),+ });withRow(world, 'ClicksRow', (row) => {const label = world.findEntityByName('ClicksLabel');@@ -98,18 +87,14 @@ export const buildSystem = defineSystem(withRow(world, 'VolumeRow', (row) => {const label = world.findEntityByName('VolumeLabel');- const slider = createSlider({- world, parent: row,+ // Input is built in: drag the track, or Tab to it and use the+ // arrow keys.+ state.slider = createSlider({+ world, events, parent: row,node: slot(SLIDER_W, SLIDER_H),min: 0, max: 100, step: 1, value: 60, handleWidth: 14,onChange: (v) => { if (label !== null) setText(world, label, `Volume ${Math.round(v)}%`); },});- // createSlider ships no input; make the track hit-testable for controls.ts.- world.insert(slider.trackEntity, Interactable,- { enabled: true, blockRaycast: true, raycastTarget: true });- world.insert(slider.trackEntity, UIInteraction,- { hovered: false, pressed: false, justPressed: false, justReleased: false });- state.slider = slider;});withRow(world, 'LoadingRow', (row) => {@@ -127,7 +112,7 @@ export const buildSystem = defineSystem(node: slot(140, CONTROL_H),states: controlStates(c),text: { content: 'Open…', color: c.onPrimary, fontSize: 14 },- onClick: openDialog,+ onClick: () => dialog.open(),});});diff --git a/examples/ui-controls/src/systems/controls.ts b/examples/ui-controls/src/systems/controls.tsindex 696483d6d..e4e00724b 100644--- a/examples/ui-controls/src/systems/controls.ts+++ b/examples/ui-controls/src/systems/controls.ts@@ -1,29 +1,12 @@-import {- defineSystem, Res, GetWorld,- Time, Input, UICameraInfo, Transform, UIInteraction,-} from 'esengine';-import type { TransformData, UIInteractionData } from 'esengine';+import { defineSystem, Res, Time } from 'esengine';-import { SLIDER_W, PROGRESS_SPEED } from '../config';+import { PROGRESS_SPEED } from '../config';import { state } from '../state';export const controlsSystem = defineSystem(- [Res(Time), Res(Input), Res(UICameraInfo), GetWorld()],- (time, input, camera, world) => {- const slider = state.slider;- if (slider && camera.valid && world.valid(slider.trackEntity)) {- const inter = world.get(slider.trackEntity, UIInteraction) as UIInteractionData;- if (input.isMouseButtonPressed(0) && inter.hovered) state.dragging = true;- if (!input.isMouseButtonDown(0)) state.dragging = false;-- if (state.dragging) {- const wt = world.get(slider.trackEntity, Transform) as TransformData;- const width = SLIDER_W * wt.worldScale.x; // px == world units, times canvas scale- const left = wt.worldPosition.x - width / 2;- slider.setValue(slider.valueAtLocalX(camera.worldMouseX - left, width));- }- }-+ [Res(Time)],+ (time) => {+ // Slider input (drag + arrow keys) is built into the UISlider system.const progress = state.progress;if (progress && !state.paused) {state.progressT += time.delta * PROGRESS_SPEED * state.progressDir;diff --git a/examples/ui-layout/src/systems/build.ts b/examples/ui-layout/src/systems/build.tsindex 574941bd6..a21e0204d 100644--- a/examples/ui-layout/src/systems/build.ts+++ b/examples/ui-layout/src/systems/build.ts@@ -119,7 +119,7 @@ export const buildSystem = defineSystem(onClick: () => { set((get() + 1) % opts.length); refresh(); apply(); },});label = spawnUIEntity({- world, parent: btn, node: { fill: true },+ world, parent: btn.entity, node: { fill: true },text: { content: '', fontSize: 13, color: c.onPrimary,align: TextAlign.Center, verticalAlign: TextVerticalAlign.Middle },});diff --git a/examples/ui-list/src/systems/build.ts b/examples/ui-list/src/systems/build.tsindex 15fed3855..6354d0341 100644--- a/examples/ui-list/src/systems/build.ts+++ b/examples/ui-list/src/systems/build.ts@@ -2,6 +2,7 @@ import {defineSystem, Res, GetWorld,UIEvents,Text, UIVisual,+ uiPlugin,createListView, createButton,ArrayDataSource,spawnUIEntity,@@ -77,6 +78,7 @@ export const buildSystem = defineSystem(};state.list = createListView<Contact>({+ host: uiPlugin,world, parent: listSlot,viewportSize: { x: LIST_W, y: LIST_H },background: { color: { r: 0.11, g: 0.11, b: 0.13, a: 1 } },@@ -106,6 +108,7 @@ export const buildSystem = defineSystem(};state.grid = createListView<number>({+ host: uiPlugin,world, parent: gridSlot,viewportSize: { x: GRID_W, y: GRID_H },background: { color: { r: 0.11, g: 0.11, b: 0.13, a: 1 } },diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 21fb5a2f7..c8d8761b6 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 1204 stable · 17 beta · 1 deprecated+Symbols: 1220 stable · 17 beta · 1 deprecated## ABI_LAYOUT_HASH — const```@@ -767,7 +767,7 @@ Record<string, PrefabData>## BUILTIN_UI_WIDGET_NAMES — const```-readonly ["Button", "Toggle", "Slider", "Progress", "Dropdown", "ListView"]+readonly ["Button", "Toggle", "Slider", "Dialog", "TextInput", "Progress", "Dropdown", "ListView"]```## BUNDLE_MODES — const@@ -1064,16 +1064,25 @@ FilterEffectDef | ReverbEffectDef | CompressorEffectDef(...bindings: Binding[]) => ActionDef```+## ButtonHandle — interface+```+dispose: () => void+entity: number+setDisabled: (disabled: boolean) => void+```+## ButtonOptions — interface```background: UIVisualInit | undefineddisabled: boolean | undefinedevents: UIEventQueuefadeDuration: number | undefined+focusable: boolean | undefinednode: UINodeInit | undefinedonClick: ((entity: Entity) => void) | undefinedparent: number | undefinedstates: Record<string, ButtonStateVisual> | undefined+tabIndex: number | undefinedtext: string | TextInit | undefinedworld: World```@@ -1683,6 +1692,7 @@ data: DataSource<T> | readonly T[]decelerationRate: number | undefineddirection: "vertical" | "horizontal" | "both" | undefineddragScroll: boolean | undefined+host: ListViewHostitem: ListItemTemplate<T> | Record<string, ListItemTemplate<T>>layout: ListLayoutSpec | LayoutProvidernode: UINodeInit | undefined@@ -1856,9 +1866,9 @@ static prototype: DefaultImageResolver## DialogHandle — interface```-backdropEntity: numberclose: () => voiddispose: () => void+entity: numberisOpen: () => booleanopen: () => voidpanelEntity: number@@ -1868,6 +1878,10 @@ panelEntity: number```backdropNode: UINodeInit | undefinedbackdropVisual: UIVisualInit | undefined+closeOnBackdrop: boolean | undefined+closeOnEscape: boolean | undefined+events: UIEventQueue+onOpenChange: ((open: boolean) => void) | undefinedpanelNode: UINodeInit | undefinedpanelVisual: UIVisualInit | undefinedparent: number | undefined@@ -2905,7 +2919,7 @@ sideModules: SideModuleHost | undefined## INTERACTION_PAGES — const```-readonly ["normal", "hover", "pressed", "disabled"]+readonly ["normal", "hover", "pressed", "disabled", "focused"]```## INVALID_ENTITY — const@@ -3315,6 +3329,14 @@ scrollToIndex: (index: number) => voidview: ListView<T>```+## ListViewHost — interface+```+attachScrollContainer: (entity: Entity, container: ScrollContainer) => void+detachScrollContainer: (entity: Entity) => void+registerListView: (list: ListView<unknown>) => void+unregisterListView: (list: ListView<unknown>) => void+```+## ListViewOptions — interface```dataSource: DataSource<T>@@ -5473,6 +5495,32 @@ static new (opts: ScrollContainerOptions): ScrollContainerstatic prototype: ScrollContainer```+## ScrollViewHandle — interface+```+content: number+dispose: () => void+entity: number+scroll: ScrollContainer+scrollTo: (offset: Vec2) => void+setContentSize: (size: Vec2) => void+```++## ScrollViewOptions — interface+```+background: UIVisualInit | undefined+contentSize: Vec2+decelerationRate: number | undefined+direction: "vertical" | "horizontal" | "both" | undefined+dragScroll: boolean | undefined+host: ListViewHost+node: UINodeInit | undefined+onScroll: ((offset: Vec2) => void) | undefined+parent: number | undefined+viewportSize: Vec2+wheelSpeed: number | undefined+world: World+```+## SegmentCollider — const```BuiltinComponentDef<SegmentColliderData>@@ -5577,12 +5625,14 @@ getValue: () => numberhandleEntity: numbersetValue: (value: number) => voidtrackEntity: number-valueAtLocalX: (localX: number, trackWidth: number) => number```## SliderOptions — interface```+disabled: boolean | undefined+events: UIEventQueuefillVisual: UIVisualInit | undefined+focusable: boolean | undefinedhandleVisual: UIVisualInit | undefinedhandleWidth: number | undefinedmax: number | undefined@@ -5591,6 +5641,7 @@ node: UINodeInit | undefinedonChange: ((value: number, entity: Entity) => void) | undefinedparent: number | undefinedstep: number | undefined+tabIndex: number | undefinedtrackVisual: UIVisualInit | undefinedvalue: number | undefinedworld: World@@ -6149,6 +6200,38 @@ readOnly: booleanvalue: string```+## TextInputHandle — interface+```+dispose: () => void+entity: number+getValue: () => string+setValue: (value: string) => void+```++## TextInputOptions — interface+```+backgroundColor: Color | undefined+color: Color | undefined+disabled: boolean | undefined+events: UIEventQueue+fontFamily: string | undefined+fontSize: number | undefined+maxLength: number | undefined+multiline: boolean | undefined+node: UINodeInit | undefined+onChange: ((value: string, entity: Entity) => void) | undefined+onSubmit: ((value: string, entity: Entity) => void) | undefined+padding: number | undefined+parent: number | undefined+password: boolean | undefined+placeholder: string | undefined+placeholderColor: Color | undefined+readOnly: boolean | undefined+tabIndex: number | undefined+value: string | undefined+world: World+```+## TextInputPlugin — class```build: (app: App) => void@@ -6249,6 +6332,7 @@ ComponentDef<ThemeStyleData>## ThemeStyleData — interface```+input: { background?: ColorRole; text?: ColorRole; placeholder?: ColorRole; } | undefinedstates: Record<string, keyof ThemeColors> | undefinedtext: keyof ThemeColors | undefinedvisual: keyof ThemeColors | undefined@@ -6577,6 +6661,7 @@ ResourceDef<TimerManager>dispose: () => voidentity: numberisOn: () => boolean+setDisabled: (disabled: boolean) => voidsetIsOn: (value: boolean, silent?: boolean) => void```@@ -6586,11 +6671,13 @@ background: UIVisualInit | undefinedcheck: { node?: UINodeInit; color?: Color; sprite?: number; } | undefineddisabled: boolean | undefinedevents: UIEventQueue+focusable: boolean | undefinedinteractionStates: Record<string, ButtonStateVisual> | undefinedisOn: boolean | undefinednode: UINodeInit | undefinedonChange: ((isOn: boolean, entity: Entity) => void) | undefinedparent: number | undefined+tabIndex: number | undefinedworld: World```@@ -6840,6 +6927,17 @@ ComponentDef<UIControllerData>controllers: ControllerState[]```+## UIDialog — const+```+ComponentDef<UIDialogData>+```++## UIDialogData — interface+```+closeOnBackdrop: boolean+closeOnEscape: boolean+```+## UIDisplay — enum```Flex = 0@@ -7016,6 +7114,21 @@ static new (): UIRenderOrderPluginstatic prototype: UIRenderOrderPlugin```+## UISlider — const+```+ComponentDef<UISliderData>+```++## UISliderData — interface+```+fill: number+handle: number+max: number+min: number+step: number+value: number+```+## UIVisual — const```BuiltinComponentDef<UIVisualData>@@ -7272,6 +7385,13 @@ ComponentDef<WeldJointData>ComponentDef<WheelJointData>```+## WidgetInteractionInit — interface+```+disabled: boolean | undefined+focusable: boolean | undefined+tabIndex: number | undefined+```+## With — function```(component: AnyComponentDef): FilterExpr@@ -7725,7 +7845,7 @@ Plugin## createButton — function```-(opts: ButtonOptions): Entity+(opts: ButtonOptions): ButtonHandle```## createDialog — function@@ -7778,6 +7898,11 @@ Plugin(name: string, sceneData: SceneData | undefined, options: Omit<LoadRuntimeSceneOptions, "sceneData" | "sceneName">, scenePath?: string): SceneConfig```+## createScrollView — function+```+(opts: ScrollViewOptions): ScrollViewHandle+```+## createSlider — function```(opts: SliderOptions): SliderHandle@@ -7788,6 +7913,11 @@ Plugin(options: GameSocketOptions): PlatformSocket```+## createTextInput — function+```+(opts: TextInputOptions): TextInputHandle+```+## createTileset — function```(texture: string, tileWidth?: number, tileHeight?: number, columns?: number): TilesetAsset@@ -8358,6 +8488,11 @@ InputRouter(path: string): boolean```+## isDialogOpen — function+```+(world: World, root: Entity): boolean+```+## isEditor — function```(): boolean@@ -8478,6 +8613,11 @@ Logger(physics: Physics): LosCheck```+## makeWidgetInteractable — function+```+(world: World, entity: Entity, init?: WidgetInteractionInit): void+```+## markThemed — function```(world: World, entity: Entity, style: ThemeStyleData): void@@ -9008,6 +9148,11 @@ Plugin(ctx: AppContext): void```+## setDialogOpen — function+```+(world: World, events: UIEventQueue, root: Entity, open: boolean): void+```+## setEditorMode — function```(active: boolean): voiddiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 9ef2b4e79..715342a88 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 1203 stable · 19 beta · 1 deprecated+Symbols: 1219 stable · 19 beta · 1 deprecated## ANCHOR_AXES — const```@@ -762,7 +762,7 @@ Record<string, PrefabData>## BUILTIN_UI_WIDGET_NAMES — const```-readonly ["Button", "Toggle", "Slider", "Progress", "Dropdown", "ListView"]+readonly ["Button", "Toggle", "Slider", "Dialog", "TextInput", "Progress", "Dropdown", "ListView"]```## BUNDLE_MODES — const@@ -1059,16 +1059,25 @@ FilterEffectDef | ReverbEffectDef | CompressorEffectDef(...bindings: Binding[]) => ActionDef```+## ButtonHandle — interface+```+dispose: () => void+entity: number+setDisabled: (disabled: boolean) => void+```+## ButtonOptions — interface```background: UIVisualInit | undefineddisabled: boolean | undefinedevents: UIEventQueuefadeDuration: number | undefined+focusable: boolean | undefinednode: UINodeInit | undefinedonClick: ((entity: Entity) => void) | undefinedparent: number | undefinedstates: Record<string, ButtonStateVisual> | undefined+tabIndex: number | undefinedtext: string | TextInit | undefinedworld: World```@@ -1678,6 +1687,7 @@ data: DataSource<T> | readonly T[]decelerationRate: number | undefineddirection: "vertical" | "horizontal" | "both" | undefineddragScroll: boolean | undefined+host: ListViewHostitem: ListItemTemplate<T> | Record<string, ListItemTemplate<T>>layout: ListLayoutSpec | LayoutProvidernode: UINodeInit | undefined@@ -1851,9 +1861,9 @@ static prototype: DefaultImageResolver## DialogHandle — interface```-backdropEntity: numberclose: () => voiddispose: () => void+entity: numberisOpen: () => booleanopen: () => voidpanelEntity: number@@ -1863,6 +1873,10 @@ panelEntity: number```backdropNode: UINodeInit | undefinedbackdropVisual: UIVisualInit | undefined+closeOnBackdrop: boolean | undefined+closeOnEscape: boolean | undefined+events: UIEventQueue+onOpenChange: ((open: boolean) => void) | undefinedpanelNode: UINodeInit | undefinedpanelVisual: UIVisualInit | undefinedparent: number | undefined@@ -2900,7 +2914,7 @@ sideModules: SideModuleHost | undefined## INTERACTION_PAGES — const```-readonly ["normal", "hover", "pressed", "disabled"]+readonly ["normal", "hover", "pressed", "disabled", "focused"]```## INVALID_ENTITY — const@@ -3310,6 +3324,14 @@ scrollToIndex: (index: number) => voidview: ListView<T>```+## ListViewHost — interface+```+attachScrollContainer: (entity: Entity, container: ScrollContainer) => void+detachScrollContainer: (entity: Entity) => void+registerListView: (list: ListView<unknown>) => void+unregisterListView: (list: ListView<unknown>) => void+```+## ListViewOptions — interface```dataSource: DataSource<T>@@ -5468,6 +5490,32 @@ static new (opts: ScrollContainerOptions): ScrollContainerstatic prototype: ScrollContainer```+## ScrollViewHandle — interface+```+content: number+dispose: () => void+entity: number+scroll: ScrollContainer+scrollTo: (offset: Vec2) => void+setContentSize: (size: Vec2) => void+```++## ScrollViewOptions — interface+```+background: UIVisualInit | undefined+contentSize: Vec2+decelerationRate: number | undefined+direction: "vertical" | "horizontal" | "both" | undefined+dragScroll: boolean | undefined+host: ListViewHost+node: UINodeInit | undefined+onScroll: ((offset: Vec2) => void) | undefined+parent: number | undefined+viewportSize: Vec2+wheelSpeed: number | undefined+world: World+```+## SegmentCollider — const```BuiltinComponentDef<SegmentColliderData>@@ -5572,12 +5620,14 @@ getValue: () => numberhandleEntity: numbersetValue: (value: number) => voidtrackEntity: number-valueAtLocalX: (localX: number, trackWidth: number) => number```## SliderOptions — interface```+disabled: boolean | undefined+events: UIEventQueuefillVisual: UIVisualInit | undefined+focusable: boolean | undefinedhandleVisual: UIVisualInit | undefinedhandleWidth: number | undefinedmax: number | undefined@@ -5586,6 +5636,7 @@ node: UINodeInit | undefinedonChange: ((value: number, entity: Entity) => void) | undefinedparent: number | undefinedstep: number | undefined+tabIndex: number | undefinedtrackVisual: UIVisualInit | undefinedvalue: number | undefinedworld: World@@ -6144,6 +6195,38 @@ readOnly: booleanvalue: string```+## TextInputHandle — interface+```+dispose: () => void+entity: number+getValue: () => string+setValue: (value: string) => void+```++## TextInputOptions — interface+```+backgroundColor: Color | undefined+color: Color | undefined+disabled: boolean | undefined+events: UIEventQueue+fontFamily: string | undefined+fontSize: number | undefined+maxLength: number | undefined+multiline: boolean | undefined+node: UINodeInit | undefined+onChange: ((value: string, entity: Entity) => void) | undefined+onSubmit: ((value: string, entity: Entity) => void) | undefined+padding: number | undefined+parent: number | undefined+password: boolean | undefined+placeholder: string | undefined+placeholderColor: Color | undefined+readOnly: boolean | undefined+tabIndex: number | undefined+value: string | undefined+world: World+```+## TextInputPlugin — class```build: (app: App) => void@@ -6244,6 +6327,7 @@ ComponentDef<ThemeStyleData>## ThemeStyleData — interface```+input: { background?: ColorRole; text?: ColorRole; placeholder?: ColorRole; } | undefinedstates: Record<string, keyof ThemeColors> | undefinedtext: keyof ThemeColors | undefinedvisual: keyof ThemeColors | undefined@@ -6572,6 +6656,7 @@ ResourceDef<TimerManager>dispose: () => voidentity: numberisOn: () => boolean+setDisabled: (disabled: boolean) => voidsetIsOn: (value: boolean, silent?: boolean) => void```@@ -6581,11 +6666,13 @@ background: UIVisualInit | undefinedcheck: { node?: UINodeInit; color?: Color; sprite?: number; } | undefineddisabled: boolean | undefinedevents: UIEventQueue+focusable: boolean | undefinedinteractionStates: Record<string, ButtonStateVisual> | undefinedisOn: boolean | undefinednode: UINodeInit | undefinedonChange: ((isOn: boolean, entity: Entity) => void) | undefinedparent: number | undefined+tabIndex: number | undefinedworld: World```@@ -6835,6 +6922,17 @@ ComponentDef<UIControllerData>controllers: ControllerState[]```+## UIDialog — const+```+ComponentDef<UIDialogData>+```++## UIDialogData — interface+```+closeOnBackdrop: boolean+closeOnEscape: boolean+```+## UIDisplay — enum```Flex = 0@@ -7011,6 +7109,21 @@ static new (): UIRenderOrderPluginstatic prototype: UIRenderOrderPlugin```+## UISlider — const+```+ComponentDef<UISliderData>+```++## UISliderData — interface+```+fill: number+handle: number+max: number+min: number+step: number+value: number+```+## UIVisual — const```BuiltinComponentDef<UIVisualData>@@ -7267,6 +7380,13 @@ ComponentDef<WeldJointData>ComponentDef<WheelJointData>```+## WidgetInteractionInit — interface+```+disabled: boolean | undefined+focusable: boolean | undefined+tabIndex: number | undefined+```+## With — function```(component: AnyComponentDef): FilterExpr@@ -7720,7 +7840,7 @@ Plugin## createButton — function```-(opts: ButtonOptions): Entity+(opts: ButtonOptions): ButtonHandle```## createDialog — function@@ -7773,6 +7893,11 @@ Plugin(name: string, sceneData: SceneData | undefined, options: Omit<LoadRuntimeSceneOptions, "sceneData" | "sceneName">, scenePath?: string): SceneConfig```+## createScrollView — function+```+(opts: ScrollViewOptions): ScrollViewHandle+```+## createSlider — function```(opts: SliderOptions): SliderHandle@@ -7783,6 +7908,11 @@ Plugin(options: GameSocketOptions): PlatformSocket```+## createTextInput — function+```+(opts: TextInputOptions): TextInputHandle+```+## createTileset — function```(texture: string, tileWidth?: number, tileHeight?: number, columns?: number): TilesetAsset@@ -8353,6 +8483,11 @@ InputRouter(path: string): boolean```+## isDialogOpen — function+```+(world: World, root: Entity): boolean+```+## isEditor — function```(): boolean@@ -8478,6 +8613,11 @@ Logger(physics: Physics): LosCheck```+## makeWidgetInteractable — function+```+(world: World, entity: Entity, init?: WidgetInteractionInit): void+```+## markThemed — function```(world: World, entity: Entity, style: ThemeStyleData): void@@ -9013,6 +9153,11 @@ Plugin(ctx: AppContext): void```+## setDialogOpen — function+```+(world: World, events: UIEventQueue, root: Entity, open: boolean): void+```+## setEditorMode — function```(active: boolean): voiddiff --git a/sdk/src/core-ui.ts b/sdk/src/core-ui.tsindex 76e1976d0..fdd098836 100644--- a/sdk/src/core-ui.ts+++ b/sdk/src/core-ui.ts@@ -177,18 +177,27 @@ export {createButton,setButtonState,themeButtonStates,+ makeWidgetInteractable,+ type WidgetInteractionInit,type ButtonOptions,+ type ButtonHandle,type ButtonStateVisual,createToggle,type ToggleOptions,type ToggleHandle,createSlider,+ UISlider,+ type UISliderData,type SliderOptions,type SliderHandle,createProgress,type ProgressOptions,type ProgressHandle,createDialog,+ UIDialog,+ isDialogOpen,+ setDialogOpen,+ type UIDialogData,type DialogOptions,type DialogHandle,createDropdown,@@ -199,8 +208,15 @@ export {createListView,type CreateListViewOptions,type ListViewHandle,+ type ListViewHost,type ListItemTemplate,type ListLayoutSpec,+ createTextInput,+ type TextInputOptions,+ type TextInputHandle,+ createScrollView,+ type ScrollViewOptions,+ type ScrollViewHandle,ListView,type ListViewOptions,ScrollContainer,diff --git a/sdk/src/prefab/sceneInstance.ts b/sdk/src/prefab/sceneInstance.tsindex 301d57004..b9da16e23 100644--- a/sdk/src/prefab/sceneInstance.ts+++ b/sdk/src/prefab/sceneInstance.ts@@ -29,6 +29,7 @@import { flattenPrefab } from './flatten';import { diffAgainstSource } from './diff';import { cloneComponents } from './clone';+import { getComponent } from '../component';import { PREFAB_FORMAT_VERSION } from './migrate';import type {PrefabData,@@ -218,10 +219,29 @@ export interface ExtractEntity {* components are deep-cloned so the asset owns its own data. Emits the current* prefab format, so no migration runs on load.*- * NOTE: component fields that REFERENCE another entity by id are left as-is —- * remapping internal entity links to prefab ids is a later refinement; the- * common case (no intra-prefab entity refs) round-trips exactly.+ * Component fields that REFERENCE another entity (declared via the component's+ * `entityFields` metadata) are remapped to prefab-local ids when the target is+ * inside the subtree; instantiation maps them back (see remapComponentEntityRefs).+ * A reference pointing outside the subtree is left numeric and will dangle.*/+/** Capture-side twin of remapComponentEntityRefs: runtime id → prefab-local id. */+function captureEntityRefs(+ components: ComponentData[],+ idMap: Map<number, string>,+): ComponentData[] {+ for (const comp of components) {+ const def = getComponent(comp.type);+ if (!def || def.entityFields.length === 0) continue;+ for (const field of def.entityFields) {+ const value = comp.data[field];+ if (typeof value === 'number' && idMap.has(value)) {+ comp.data[field] = idMap.get(value)!;+ }+ }+ }+ return components;+}+export function extractPrefab(entities: readonly ExtractEntity[],rootId: number,@@ -238,7 +258,7 @@ export function extractPrefab(name: e.name,parent: e.id === rootId ? null : inSubtree(e.parent) ? idMap.get(e.parent!)! : null,children: e.children.filter((c) => idMap.has(c)).map((c) => idMap.get(c)!),- components: cloneComponents(e.components),+ components: captureEntityRefs(cloneComponents(e.components), idMap),visible: e.visible ?? true,}));diff --git a/sdk/src/ui/ARCHITECTURE.md b/sdk/src/ui/ARCHITECTURE.mdindex 42eb94396..4d1cf49c2 100644--- a/sdk/src/ui/ARCHITECTURE.md+++ b/sdk/src/ui/ARCHITECTURE.md@@ -43,13 +43,13 @@ collection, or widgets.| `layout/` | Flexbox layout + safe area + layout bookkeeping | `anchor`, `flex`, `layout` (Yoga driver plugin), `safe-area`, `ui-layout-generation` || `input/` | Pointer/keyboard interaction primitives + their plugins | `interactable`, `draggable`, `focusable`, `drag`, `focus`, `interaction` || `controller/` | The one widget-state mechanism: named pages + per-component property gears, tween-applied | `ui-controller`, `ui-gear`, `gear-apply`, `bind-page`, `ai-builtins`, `plugin` |-| `behavior/` | Runtime systems for scroll/collection ticking + theme re-resolution | `plugin` (UIBehaviorPlugin), `theme-apply` |+| `behavior/` | Runtime systems: scroll/collection ticking, data-driven widget behavior, theme re-resolution | `plugin` (UIBehaviorPlugin), `dialog`, `slider`, `theme-apply` || `render/` | UI-specific render concerns | `mask`, `render-order` || `collection/` | Data-driven collections + view recycling | `list-view`, `scroll-container`, `view-pool`, `data-source`, `layout-provider` || `text/` | SDF glyph atlas, text layout, rich text, editable text | `glyph-atlas`, `text-renderer`, `layout`, `rich-text-*`, `text-input`, `image-resolver` || `theme/` | Design tokens + per-entity role markers | `tokens`, `theme-style` || `util/` | Cross-cutting helpers (no engine state of their own) | `helpers`, `math`, `constants`, `property-path`, `ui-pick` |-| `widgets/` | Layer-4 widget **factory functions** + their prefab capture | `button`, `toggle`, `slider`, `progress`, `dialog`, `dropdown`, `list-view`, `helpers`, `toPrefab`, `prefabs/` |+| `widgets/` | Layer-4 widget **factory functions** + their prefab capture | `button`, `toggle`, `slider`, `progress`, `dialog`, `dropdown`, `text-input`, `list-view`, `scroll-view`, `helpers`, `toPrefab`, `prefabs/` |Only two files live at the module root, and that is deliberate:diff --git a/sdk/src/ui/behavior/dialog.ts b/sdk/src/ui/behavior/dialog.tsnew file mode 100644index 000000000..3e537b5bd--- /dev/null+++ b/sdk/src/ui/behavior/dialog.ts@@ -0,0 +1,70 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file ui/behavior/dialog.ts+ * @brief UIDialog — data-driven modal dismissal.+ *+ * The component lives on the dialog's backdrop root; its open state IS the+ * root's `UINode.display` (no shadow state to desync). The system owns the two+ * standard dismissal affordances — Escape and a click on the backdrop scrim —+ * so a dialog instantiated from a prefab behaves without any code hookup.+ * `createDialog` composes this; the panel swallows clicks with its own+ * Interactable, so only true scrim clicks dismiss.+ */+import { defineComponent } from '../../component';+import { defineSystem, type SystemDef } from '../../system';+import { Res } from '../../resource';+import { Input, type InputState } from '../../input';+import type { World } from '../../world';+import type { Entity } from '../../types';+import { UINode, UIDisplay, type UINodeData } from '../core/ui-node';+import { UIInteraction, type UIInteractionData } from '../input/interactable';+import { UIEventType, type UIEventQueue } from '../core/events';++export interface UIDialogData {+ /** Escape closes the dialog while open. */+ closeOnEscape: boolean;+ /** A click on the backdrop scrim (not the panel) closes the dialog. */+ closeOnBackdrop: boolean;+}++export const UIDialog = defineComponent<UIDialogData>('UIDialog', {+ closeOnEscape: true,+ closeOnBackdrop: true,+});++/** True when the dialog root's subtree is displayed. */+export function isDialogOpen(world: World, root: Entity): boolean {+ if (!world.has(root, UINode)) return false;+ return (world.get(root, UINode) as UINodeData).display !== UIDisplay.None;+}++/** Show/hide the dialog subtree and emit `change` with the new open state. */+export function setDialogOpen(+ world: World, events: UIEventQueue, root: Entity, open: boolean,+): void {+ if (!world.has(root, UINode) || isDialogOpen(world, root) === open) return;+ const node = world.get(root, UINode) as UINodeData;+ node.display = open ? UIDisplay.Flex : UIDisplay.None;+ world.insert(root, UINode, node);+ events.emit(root, UIEventType.Change, { open });+}++/** Applies UIDialog's dismissal affordances to every open dialog. */+export function createDialogSystem(world: World, events: UIEventQueue): SystemDef {+ return defineSystem([Res(Input)], (input: InputState) => {+ const escape = input.isKeyPressed('Escape');+ for (const e of world.getEntitiesWithComponents([UIDialog, UINode])) {+ if (!isDialogOpen(world, e)) continue;+ const d = world.get(e, UIDialog) as UIDialogData;++ const scrimClicked = d.closeOnBackdrop+ && world.has(e, UIInteraction)+ && (world.get(e, UIInteraction) as UIInteractionData).justPressed;++ if ((d.closeOnEscape && escape) || scrimClicked) {+ setDialogOpen(world, events, e, false);+ }+ }+ }, { name: 'UIDialogSystem' });+}diff --git a/sdk/src/ui/behavior/plugin.ts b/sdk/src/ui/behavior/plugin.tsindex f77281f9c..2b3d548cb 100644--- a/sdk/src/ui/behavior/plugin.ts+++ b/sdk/src/ui/behavior/plugin.ts@@ -16,6 +16,9 @@ import { ScrollContainer, ScrollContainerRegistry } from '../collection/scroll-cimport { KineticScroll } from '../collection/kinetic-scroll';import { UIInteraction, type UIInteractionData } from '../input/interactable';import { getEntityDepth } from '../util/helpers';+import { UIDialog, createDialogSystem } from './dialog';+import { UISlider, createSliderSystem } from './slider';+import { registerComponent } from '../../component';/** Screen-px slop before a press becomes a scroll drag (matches Draggable). */const SCROLL_DRAG_THRESHOLD_PX = 5;@@ -90,6 +93,20 @@ export class UIBehaviorPlugin implements Plugin {const world = app.world;+ registerComponent('UIDialog', UIDialog);+ app.addSystemToSchedule(+ Schedule.Update,+ createDialogSystem(world, events),+ { runIf: playModeOnly },+ );++ registerComponent('UISlider', UISlider);+ app.addSystemToSchedule(+ Schedule.Update,+ createSliderSystem(world, events),+ { runIf: playModeOnly },+ );+app.addSystemToSchedule(Schedule.Update,defineSystem([], () => listViews.tick(), { name: 'ListViewSystem' }),diff --git a/sdk/src/ui/behavior/slider.ts b/sdk/src/ui/behavior/slider.tsnew file mode 100644index 000000000..7a4ff9795--- /dev/null+++ b/sdk/src/ui/behavior/slider.ts@@ -0,0 +1,150 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file ui/behavior/slider.ts+ * @brief UISlider — data-driven slider state + input.+ *+ * The component IS the slider's state (min/max/step/value + its fill/handle+ * entity refs); the system is the single writer of the visuals, re-deriving+ * them whenever `value` differs from what's on screen. Any writer — pointer+ * drag, keyboard, `handle.setValue`, a data binding, the editor inspector —+ * just writes `value`, and change events fire uniformly for all of them.+ */+import { defineComponent } from '../../component';+import { defineSystem, type SystemDef } from '../../system';+import { Res } from '../../resource';+import { Input, type InputState } from '../../input';+import { Transform, type TransformData } from '../../component';+import type { World } from '../../world';+import type { Entity } from '../../types';+import { UIVisual, type UIVisualData } from '../core/ui-visual';+import { UINode, type UINodeData } from '../core/ui-node';+import { percent } from '../core/dimension';+import { UICameraInfo, type UICameraData } from '../core/ui-camera-info';+import { UIInteraction, type UIInteractionData } from '../input/interactable';+import { Interactable, type InteractableData } from '../input/interactable';+import { Focusable, type FocusableData } from '../input/focusable';+import { UIEventType, type UIEventQueue } from '../core/events';+import { EntityStateMap, getUINodeWidth } from '../util/helpers';++export interface UISliderData {+ min: number;+ max: number;+ /** Quantization step; 0 = continuous. */+ step: number;+ value: number;+ /** The Filled fill bar entity (fillAmount tracks the value fraction). */+ fill: Entity;+ /** The handle thumb entity (insetLeft tracks the value fraction). */+ handle: Entity;+}++export const UISlider = defineComponent<UISliderData>('UISlider', {+ min: 0,+ max: 1,+ step: 0,+ value: 0,+ fill: 0 as Entity,+ handle: 0 as Entity,+}, { entityFields: ['fill', 'handle'] });++export function sliderClamp(v: number, d: { min: number; max: number; step: number }): number {+ const clamped = v < d.min ? d.min : v > d.max ? d.max : v;+ if (d.step <= 0) return clamped;+ const snapped = Math.round((clamped - d.min) / d.step) * d.step + d.min;+ return snapped < d.min ? d.min : snapped > d.max ? d.max : snapped;+}++export function sliderFraction(d: { min: number; max: number; value: number }): number {+ if (d.max <= d.min) return 0;+ const t = (d.value - d.min) / (d.max - d.min);+ return t < 0 ? 0 : t > 1 ? 1 : t;+}++/** Keyboard nudge: explicit step, else 1% of the range. */+function keyStep(d: UISliderData): number {+ return d.step > 0 ? d.step : (d.max - d.min) / 100;+}++/**+ * Pointer drag (press-capture on the track), keyboard (arrows/Home/End while+ * focused), and value→visual sync for every UISlider.+ */+export function createSliderSystem(world: World, events: UIEventQueue): SystemDef {+ // Press on a track captures the drag until release, even off-entity.+ let active: Entity | null = null;+ const shown = new EntityStateMap<number>(); // last value whose visuals were applied++ return defineSystem(+ [Res(Input), Res(UICameraInfo)],+ (input: InputState, camera: UICameraData) => {+ for (const e of world.getEntitiesWithComponents([UISlider])) {+ const d = world.get(e, UISlider) as UISliderData;+ let next = d.value;++ const enabled = !world.has(e, Interactable)+ || (world.get(e, Interactable) as InteractableData).enabled;++ // Pointer: capture on press, track while held.+ if (enabled && world.has(e, UIInteraction)+ && (world.get(e, UIInteraction) as UIInteractionData).justPressed) {+ active = e;+ }+ if (active === e) {+ if (!input.isMouseButtonDown(0)) {+ active = null;+ } else if (camera.valid && world.has(e, Transform)) {+ const t = world.get(e, Transform) as TransformData;+ const w = getUINodeWidth(e) * t.worldScale.x;+ if (w > 0) {+ const left = t.worldPosition.x - w / 2;+ next = sliderClamp(+ d.min + ((camera.worldMouseX - left) / w) * (d.max - d.min), d);+ }+ }+ }++ // Keyboard while focused.+ if (enabled && world.has(e, Focusable)+ && (world.get(e, Focusable) as FocusableData).isFocused) {+ const s = keyStep(d);+ if (input.isKeyPressed('ArrowLeft') || input.isKeyPressed('ArrowDown')) {+ next = sliderClamp(next - s, d);+ }+ if (input.isKeyPressed('ArrowRight') || input.isKeyPressed('ArrowUp')) {+ next = sliderClamp(next + s, d);+ }+ if (input.isKeyPressed('Home')) next = d.min;+ if (input.isKeyPressed('End')) next = d.max;+ }++ if (next !== d.value) {+ d.value = next;+ world.insert(e, UISlider, d);+ }++ // Value → visuals + change event, whoever wrote the value.+ if (shown.get(e) !== d.value) {+ const emitChange = shown.has(e); // first sync is initial paint, not a change+ shown.set(e, d.value);+ const frac = sliderFraction(d);+ if (world.valid(d.fill) && world.has(d.fill, UIVisual)) {+ const vis = world.get(d.fill, UIVisual) as UIVisualData;+ if (vis.fillAmount !== frac) {+ vis.fillAmount = frac;+ world.insert(d.fill, UIVisual, vis);+ }+ }+ if (world.valid(d.handle) && world.has(d.handle, UINode)) {+ const n = world.get(d.handle, UINode) as UINodeData;+ n.insetLeft = percent(frac * 100);+ world.insert(d.handle, UINode, n);+ }+ if (emitChange) events.emit(e, UIEventType.Change, { value: d.value });+ }+ }+ shown.cleanup(world);+ },+ { name: 'UISliderSystem' },+ );+}diff --git a/sdk/src/ui/behavior/theme-apply.ts b/sdk/src/ui/behavior/theme-apply.tsindex b2adc3a08..afb540d59 100644--- a/sdk/src/ui/behavior/theme-apply.ts+++ b/sdk/src/ui/behavior/theme-apply.ts@@ -19,6 +19,7 @@ import { UIVisual, type UIVisualData } from '../core/ui-visual';import { Text, type TextData } from '../core/text';import { INTERACTION_CONTROLLER } from '../controller/ui-controller';import { UIGear, type UIGearData } from '../controller/ui-gear';+import { TextInput, type TextInputData } from '../text/text-input';/*** Re-resolve every {@link ThemeStyle} entity's role bindings and write the active@@ -42,6 +43,17 @@ export function applyThemeToWorld(world: World): void {const c = colors[s.text];world.insert(e, Text, { ...t, color: { r: c.r, g: c.g, b: c.b, a: t.color.a } });}+ if (s.input && world.has(e, TextInput)) {+ const ti = world.get(e, TextInput) as TextInputData;+ const dye = (role: keyof typeof colors | undefined, cur: Color): Color =>+ role ? { r: colors[role].r, g: colors[role].g, b: colors[role].b, a: cur.a } : cur;+ world.insert(e, TextInput, {+ ...ti,+ backgroundColor: dye(s.input.background, ti.backgroundColor),+ color: dye(s.input.text, ti.color),+ placeholderColor: dye(s.input.placeholder, ti.placeholderColor),+ });+ }if (s.states && world.has(e, UIGear)) {const g = world.get(e, UIGear) as UIGearData;const bindings = g.bindings.map((b) => {diff --git a/sdk/src/ui/controller/gear-apply.ts b/sdk/src/ui/controller/gear-apply.tsindex e836044f0..7c6f6117c 100644--- a/sdk/src/ui/controller/gear-apply.ts+++ b/sdk/src/ui/controller/gear-apply.ts@@ -23,6 +23,7 @@ import { Res, Time, type TimeData } from '../../resource';import { applyEasing } from '../../animation/Easing';import { EntityStateMap } from '../util/helpers';import { Interactable, UIInteraction, type InteractableData, type UIInteractionData } from '../input/interactable';+import { Focusable, type FocusableData } from '../input/focusable';import type { Entity } from '../../types';import type { World } from '../../world';import {@@ -113,7 +114,7 @@ export function lerpGearValue(from: unknown, to: unknown, t: number): unknown {* the driver must not steal it back.*/const DRIVER_OWNED_PAGES: ReadonlySet<string> = new Set([- '', 'normal', 'hover', 'pressed', 'disabled',+ '', 'normal', 'hover', 'pressed', 'disabled', 'focused',]);/**@@ -123,10 +124,12 @@ const DRIVER_OWNED_PAGES: ReadonlySet<string> = new Set([export function driverStateFor(enabled: boolean,interaction: UIInteractionData | null,+ focused = false,): string {if (!enabled) return 'disabled';if (interaction?.pressed) return 'pressed';if (interaction?.hovered) return 'hover';+ if (focused) return 'focused';return 'normal';}@@ -148,7 +151,9 @@ export function createInteractionControllerDriverSystem(world: World): SystemDef? (world.get(e, UIInteraction) as UIInteractionData): null;const interactable = world.get(e, Interactable) as InteractableData;- const next = driverStateFor(interactable.enabled, inter);+ const focused = world.has(e, Focusable)+ && (world.get(e, Focusable) as FocusableData).isFocused;+ const next = driverStateFor(interactable.enabled, inter, focused);if (next !== ctrl.current && ctrl.pages.includes(next)) {ctrl.current = next;world.insert(e, UIController, data);diff --git a/sdk/src/ui/controller/ui-controller.ts b/sdk/src/ui/controller/ui-controller.tsindex e69e726ef..fcdda37dc 100644--- a/sdk/src/ui/controller/ui-controller.ts+++ b/sdk/src/ui/controller/ui-controller.ts@@ -48,7 +48,7 @@ export const UIController = defineComponent<UIControllerData>('UIController', {export const INTERACTION_CONTROLLER = '$interaction';/** Canonical interaction pages, in the order the driver prefers them. */-export const INTERACTION_PAGES = ['normal', 'hover', 'pressed', 'disabled'] as const;+export const INTERACTION_PAGES = ['normal', 'hover', 'pressed', 'disabled', 'focused'] as const;/** Build an interaction ControllerState (defaults to the 4 canonical pages). */export function interactionController(pages: string[] = [...INTERACTION_PAGES]): ControllerState {diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.tsindex 52b15761a..5b1f1ad2d 100644--- a/sdk/src/ui/index.ts+++ b/sdk/src/ui/index.ts@@ -110,6 +110,22 @@ export {export { UIBehaviorPlugin, uiBehaviorPlugin } from './behavior/plugin';+export {+ UIDialog,+ isDialogOpen,+ setDialogOpen,+ createDialogSystem,+ type UIDialogData,+} from './behavior/dialog';++export {+ UISlider,+ sliderClamp,+ sliderFraction,+ createSliderSystem,+ type UISliderData,+} from './behavior/slider';+// ─── Controllers + Gears (shared UI state) ──────────────────────────────────export {@@ -201,12 +217,14 @@ export {buildText,spawnUIEntity,setUIVisible,+ makeWidgetInteractable,FILL_AXIS,type LinearFillDirection,type UINodeInit,type UIVisualInit,type TextInit,type UIEntityInit,+ type WidgetInteractionInit,} from './widgets/helpers';export {@@ -215,9 +233,22 @@ export {themeButtonStates,interactionGears,type ButtonOptions,+ type ButtonHandle,type ButtonStateVisual,} from './widgets/button';+export {+ createTextInput,+ type TextInputOptions,+ type TextInputHandle,+} from './widgets/text-input';++export {+ createScrollView,+ type ScrollViewOptions,+ type ScrollViewHandle,+} from './widgets/scroll-view';+export {createToggle,type ToggleOptions,@@ -252,6 +283,7 @@ export {createListView,type CreateListViewOptions,type ListViewHandle,+ type ListViewHost,type ListItemTemplate,type ListLayoutSpec,} from './widgets/list-view';diff --git a/sdk/src/ui/input/focus.ts b/sdk/src/ui/input/focus.tsindex 3a167e521..2f8da254c 100644--- a/sdk/src/ui/input/focus.ts+++ b/sdk/src/ui/input/focus.ts@@ -13,8 +13,9 @@ import { Interactable } from './interactable';import type { InteractableData } from './interactable';import { UIInteraction } from './interactable';import type { UIInteractionData } from './interactable';+import { TextInput } from '../text/text-input';import { playModeOnly } from '../../env';-import { UIEvents, UIEventQueue } from '../core/events';+import { UIEvents, UIEventQueue, UIEventType } from '../core/events';import { PluginName } from '../../systemLabels';export class FocusPlugin implements Plugin {@@ -37,14 +38,33 @@ export class FocusPlugin implements Plugin {const focusableEntities = world.getEntitiesWithComponents([Focusable]);+ let pressedFocusable = false;for (const entity of focusableEntities) {if (!world.has(entity, UIInteraction)) continue;const interaction = world.get(entity, UIInteraction) as UIInteractionData;if (interaction.justPressed) {+ pressedFocusable = true;setFocus(entity);}}+ // A press anywhere that is not a focusable clears focus, and so+ // does Escape — standard focus-dismissal affordances.+ if (focusManager.focusedEntity !== null) {+ const pressedElsewhere = input.isMouseButtonPressed(0) && !pressedFocusable;+ if (pressedElsewhere || input.isKeyPressed('Escape')) clearFocus();+ }++ // Keyboard activation: Enter/Space on the focused control acts as+ // a click. Text fields consume those keys for editing instead.+ const focused = focusManager.focusedEntity;+ if (focused !== null && world.valid(focused) && !world.has(focused, TextInput)+ && (input.isKeyPressed('Enter') || input.isKeyPressed('Space'))) {+ const enabled = !world.has(focused, Interactable)+ || (world.get(focused, Interactable) as InteractableData).enabled;+ if (enabled) events.emit(focused, UIEventType.Click);+ }+if (input.isKeyPressed('Tab')) {const sorted = getSortedFocusables();if (sorted.length === 0) return;@@ -85,16 +105,25 @@ export class FocusPlugin implements Plugin {const prev = focusManager.focusedEntity;if (prev === entity) return;- if (prev !== null && world.valid(prev) && world.has(prev, Focusable)) {- const prevF = world.get(prev, Focusable) as FocusableData;- prevF.isFocused = false;- events.emit(prev, 'blur');- }-+ blurEntity(prev);focusManager.focus(entity);const f = world.get(entity, Focusable) as FocusableData;f.isFocused = true;- events.emit(entity, 'focus');+ world.insert(entity, Focusable, f);+ events.emit(entity, UIEventType.Focus);+ }++ function clearFocus(): void {+ blurEntity(focusManager.focusedEntity);+ focusManager.blur();+ }++ function blurEntity(entity: Entity | null): void {+ if (entity === null || !world.valid(entity) || !world.has(entity, Focusable)) return;+ const f = world.get(entity, Focusable) as FocusableData;+ f.isFocused = false;+ world.insert(entity, Focusable, f);+ events.emit(entity, UIEventType.Blur);}},{ name: 'FocusSystem' }diff --git a/sdk/src/ui/theme/theme-style.ts b/sdk/src/ui/theme/theme-style.tsindex 9ddb3b2c1..09fc3eeb7 100644--- a/sdk/src/ui/theme/theme-style.ts+++ b/sdk/src/ui/theme/theme-style.ts@@ -28,6 +28,9 @@ export interface ThemeStyleData {text?: ColorRole;/** Page-name → role, for each `$interaction` colour-gear page. */states?: Record<string, ColorRole>;+ /** Roles that drive a `TextInput`'s background / text / placeholder colors+ * (the input plugin owns its UIVisual, so those fields are the source). */+ input?: { background?: ColorRole; text?: ColorRole; placeholder?: ColorRole };}// The default DECLARES the fields (even though all are optional): `insert`@@ -35,7 +38,7 @@ export interface ThemeStyleData {// every role a widget tags (e.g. a dialog's `{ visual: 'backdrop' }`).export const ThemeStyle = defineComponent<ThemeStyleData>('ThemeStyle',- { visual: undefined, text: undefined, states: {} },+ { visual: undefined, text: undefined, states: {}, input: undefined },);/** Tag `entity` so the active theme's colors re-resolve onto it (seediff --git a/sdk/src/ui/widgets/button.ts b/sdk/src/ui/widgets/button.tsindex 14120aa7b..e9d4c031f 100644--- a/sdk/src/ui/widgets/button.ts+++ b/sdk/src/ui/widgets/button.ts@@ -3,7 +3,7 @@import type { Color, Entity } from '../../types';import type { World } from '../../world';-import { Interactable, UIInteraction, type InteractableData } from '../input/interactable';+import { Interactable, type InteractableData } from '../input/interactable';import {UIController,INTERACTION_CONTROLLER,@@ -19,6 +19,7 @@ import { markThemed } from '../theme/theme-style';import {spawnUIEntity,+ makeWidgetInteractable,type UINodeInit,type UIVisualInit,type TextInit,@@ -56,9 +57,19 @@ export interface ButtonOptions {fadeDuration?: number;/** Start in the disabled state (Interactable.enabled = false). */disabled?: boolean;+ /** Participate in Tab traversal + Enter/Space activation. Default true. */+ focusable?: boolean;+ /** Tab order within the focus ring. Default 0 (document order). */+ tabIndex?: number;onClick?: (entity: Entity) => void;}+export interface ButtonHandle {+ readonly entity: Entity;+ setDisabled(disabled: boolean): void;+ dispose(): void;+}+/*** Fold the state-name → override record into per-field gear bindings on the* `$interaction` controller. A field a state doesn't override gets no page@@ -104,6 +115,8 @@ export function themeButtonStates(): Record<string, ButtonStateVisual> {hover: { color: c.controlHover },pressed: { color: c.controlActive },disabled: { color: { ...c.control, a: c.control.a * 0.5 } },+ // Keyboard focus reads as hover — there is no ring primitive (yet).+ focused: { color: c.controlHover },};}@@ -114,7 +127,7 @@ export function themeButtonStates(): Record<string, ButtonStateVisual> {* Click comes straight from the interaction layer's `click` event (released* while still over the button); the handler is gated on Interactable.enabled.*/-export function createButton(opts: ButtonOptions): Entity {+export function createButton(opts: ButtonOptions): ButtonHandle {const { world, events } = opts;const entity = spawnUIEntity({@@ -124,13 +137,10 @@ export function createButton(opts: ButtonOptions): Entity {visual: opts.background ?? {},});- world.insert(entity, Interactable, {- enabled: !opts.disabled,- blockRaycast: true,- raycastTarget: true,- });- world.insert(entity, UIInteraction, {- hovered: false, pressed: false, justPressed: false, justReleased: false,+ makeWidgetInteractable(world, entity, {+ disabled: opts.disabled,+ focusable: opts.focusable,+ tabIndex: opts.tabIndex,});const states = opts.states ?? themeButtonStates();@@ -149,7 +159,10 @@ export function createButton(opts: ButtonOptions): Entity {// colors are the caller's own.if (opts.states === undefined) {markThemed(world, entity, {- states: { normal: 'control', hover: 'controlHover', pressed: 'controlActive', disabled: 'control' },+ states: {+ normal: 'control', hover: 'controlHover', pressed: 'controlActive',+ disabled: 'control', focused: 'controlHover',+ },});}@@ -166,15 +179,30 @@ export function createButton(opts: ButtonOptions): Entity {if (userText.color === undefined) markThemed(world, label, { text: 'text' });}+ let offClick: (() => void) | undefined;if (opts.onClick) {const handler = opts.onClick;- events.on(entity, UIEventType.Click, () => {+ offClick = events.on(entity, UIEventType.Click, () => {const interactable = world.get(entity, Interactable) as InteractableData;if (interactable.enabled) handler(entity);});}- return entity;+ return {+ entity,+ setDisabled: (disabled: boolean) => {+ if (!world.valid(entity)) return;+ const i = world.get(entity, Interactable) as InteractableData;+ if (i.enabled !== !disabled) {+ i.enabled = !disabled;+ world.insert(entity, Interactable, i);+ }+ },+ dispose: () => {+ offClick?.();+ if (world.valid(entity)) world.despawn(entity);+ },+ };}/**diff --git a/sdk/src/ui/widgets/dialog.ts b/sdk/src/ui/widgets/dialog.tsindex 854ff70d2..1469b51f0 100644--- a/sdk/src/ui/widgets/dialog.ts+++ b/sdk/src/ui/widgets/dialog.ts@@ -3,16 +3,17 @@import type { Entity } from '../../types';import type { World } from '../../world';-import { Interactable, UIInteraction } from '../input/interactable';--import { spawnUIEntity, type UINodeInit, type UIVisualInit } from './helpers';+import { spawnUIEntity, makeWidgetInteractable, type UINodeInit, type UIVisualInit } from './helpers';import { UINode, UIDisplay, type UINodeData } from '../core/ui-node';import { px, percent } from '../core/dimension';import { themeColors } from '../theme/tokens';import { markThemed } from '../theme/theme-style';+import { UIDialog, isDialogOpen, setDialogOpen } from '../behavior/dialog';+import type { UIEventQueue } from '../core/events';export interface DialogOptions {world: World;+ events: UIEventQueue;parent?: Entity;/** Full-viewport backdrop. Default: fill the parent. */backdropNode?: UINodeInit;@@ -23,10 +24,16 @@ export interface DialogOptions {panelVisual?: UIVisualInit;/** Start hidden. Default true. */startHidden?: boolean;+ /** Escape closes the dialog. Default true. */+ closeOnEscape?: boolean;+ /** Clicking the backdrop scrim (not the panel) closes the dialog. Default true. */+ closeOnBackdrop?: boolean;+ /** Fires on every open/close, whoever initiated it (code, Escape, scrim). */+ onOpenChange?: (open: boolean) => void;}export interface DialogHandle {- readonly backdropEntity: Entity;+ readonly entity: Entity;readonly panelEntity: Entity;isOpen(): boolean;open(): void;@@ -35,14 +42,16 @@ export interface DialogHandle {}/**- * Modal dialog: backdrop entity (blocks clicks behind it) with a- * centered panel child. Hidden by default; `open()` / `close()`- * toggle visibility + interactivity.+ * Modal dialog: a backdrop scrim (blocks clicks behind it) with a centered+ * panel child. Hidden by default; open state IS the backdrop root's+ * `UINode.display`, so hiding removes the whole subtree — including anything+ * the caller parents under `panelEntity` — from layout, rendering and input.*- * Add children to `panelEntity` to populate the dialog.+ * Dismissal (Escape / scrim click) is data-driven by the {@link UIDialog}+ * component, so a dialog instantiated from a prefab behaves without code.*/export function createDialog(opts: DialogOptions): DialogHandle {- const { world } = opts;+ const { world, events } = opts;const c = themeColors();const backdrop = spawnUIEntity({@@ -53,14 +62,12 @@ export function createDialog(opts: DialogOptions): DialogHandle {});if (!opts.backdropVisual) markThemed(world, backdrop, { visual: 'backdrop' });- // Blocks hit-test on the scene behind the dialog.- world.insert(backdrop, Interactable, {- enabled: true,- blockRaycast: true,- raycastTarget: true,- });- world.insert(backdrop, UIInteraction, {- hovered: false, pressed: false, justPressed: false, justReleased: false,+ // Blocks hit-test on the scene behind the dialog. Not focusable — the+ // scrim is an input barrier, not a control.+ makeWidgetInteractable(world, backdrop, { focusable: false });+ world.insert(backdrop, UIDialog, {+ closeOnEscape: opts.closeOnEscape ?? true,+ closeOnBackdrop: opts.closeOnBackdrop ?? true,});const panel = spawnUIEntity({@@ -79,34 +86,30 @@ export function createDialog(opts: DialogOptions): DialogHandle {visual: opts.panelVisual ?? { color: c.surface },});if (!opts.panelVisual) markThemed(world, panel, { visual: 'surface' });+ // The panel swallows clicks so only true scrim clicks reach the dismissal+ // system.+ makeWidgetInteractable(world, panel, { focusable: false });- let open = !(opts.startHidden ?? true);- applyOpen(open);-- // display:none removes the backdrop AND everything the user parented under- // the panel from layout, rendering and hit-testing in one write — closing- // must hide user content too, not just the two entities we own.- function applyOpen(value: boolean): void {+ if (opts.startHidden ?? true) {const node = world.get(backdrop, UINode) as UINodeData;- node.display = value ? UIDisplay.Flex : UIDisplay.None;+ node.display = UIDisplay.None;world.insert(backdrop, UINode, node);}+ const offChange = opts.onOpenChange+ ? events.on(backdrop, 'change', (ev) => {+ opts.onOpenChange!((ev.data as { open: boolean }).open);+ })+ : undefined;+return {- backdropEntity: backdrop,+ entity: backdrop,panelEntity: panel,- isOpen: () => open,- open: () => {- if (open) return;- open = true;- applyOpen(true);- },- close: () => {- if (!open) return;- open = false;- applyOpen(false);- },+ isOpen: () => isDialogOpen(world, backdrop),+ open: () => setDialogOpen(world, events, backdrop, true),+ close: () => setDialogOpen(world, events, backdrop, false),dispose: () => {+ offChange?.();if (world.valid(backdrop)) world.despawn(backdrop);},};diff --git a/sdk/src/ui/widgets/dropdown.ts b/sdk/src/ui/widgets/dropdown.tsindex 69faeb3f1..6063da5a2 100644--- a/sdk/src/ui/widgets/dropdown.ts+++ b/sdk/src/ui/widgets/dropdown.ts@@ -3,14 +3,13 @@import type { Color, Entity } from '../../types';import type { World } from '../../world';-import { Interactable, UIInteraction } from '../input/interactable';import { UIController, interactionController } from '../controller/ui-controller';import { UIGear } from '../controller/ui-gear';import { interactionGears } from './button';import { UIEventType, type UIEventQueue } from '../core/events';import { Text, type TextData } from '../core/text';-import { spawnUIEntity, type UINodeInit, type UIVisualInit } from './helpers';+import { spawnUIEntity, makeWidgetInteractable, type UINodeInit, type UIVisualInit } from './helpers';import { px, percent } from '../core/dimension';import { themeColors } from '../theme/tokens';import { markThemed } from '../theme/theme-style';@@ -57,10 +56,6 @@ export interface DropdownHandle<T> {dispose(): void;}-const INTERACTION_DEFAULT = {- hovered: false, pressed: false, justPressed: false, justReleased: false,-};-/** Attach a `$interaction` controller + a color gear over its three pages. */function addInteractionStates(world: World,@@ -106,8 +101,7 @@ export function createDropdown<T>(opts: DropdownOptions<T>): DropdownHandle<T> {node: opts.node ?? { fill: true },visual: { color: btnColors.normal },});- world.insert(button, Interactable, { enabled: true, blockRaycast: true, raycastTarget: true });- world.insert(button, UIInteraction, INTERACTION_DEFAULT);+ makeWidgetInteractable(world, button);addInteractionStates(world, button, btnColors);if (opts.buttonStates === undefined) {markThemed(world, button, { states: { normal: 'control', hover: 'controlHover', pressed: 'controlActive' } });@@ -182,8 +176,9 @@ export function createDropdown<T>(opts: DropdownOptions<T>): DropdownHandle<T> {},visual: { color: optColors.normal },});- world.insert(row, Interactable, { enabled: true, blockRaycast: true, raycastTarget: true });- world.insert(row, UIInteraction, INTERACTION_DEFAULT);+ // Rows are pointer-only: the popup is transient, so they stay out of+ // the Tab ring (keyboard option navigation is a later step).+ makeWidgetInteractable(world, row, { focusable: false });addInteractionStates(world, row, optColors);if (opts.optionStates === undefined) {markThemed(world, row, { states: { normal: 'control', hover: 'primaryHover', pressed: 'primaryActive' } });diff --git a/sdk/src/ui/widgets/helpers.ts b/sdk/src/ui/widgets/helpers.tsindex 824883ec6..22fee0550 100644--- a/sdk/src/ui/widgets/helpers.ts+++ b/sdk/src/ui/widgets/helpers.ts@@ -8,6 +8,8 @@ import type { Entity, Vec2 } from '../../types';import type { World } from '../../world';import { UINode, UIPositionType, UIDisplay, type UINodeData } from '../core/ui-node';+import { Interactable } from '../input/interactable';+import { Focusable } from '../input/focusable';import { px, percent, auto, type Dimension } from '../core/dimension';import { UIVisual, UIVisualType, FillMethod, FillOrigin, type UIVisualData } from '../core/ui-visual';import { Text, TextAlign, TextVerticalAlign, TextRenderMode, type TextData } from '../core/text';@@ -74,6 +76,36 @@ export function buildUINode(init: UINodeInit = {}): UINodeData {};}+export interface WidgetInteractionInit {+ /** Start disabled (Interactable.enabled = false). */+ disabled?: boolean;+ /** Participate in Tab traversal + keyboard activation. Default true. */+ focusable?: boolean;+ /** Tab order within the focus ring. Default 0 (document order). */+ tabIndex?: number;+}++/**+ * The one interaction assembly every widget shares: a raycast-blocking+ * Interactable plus (by default) a Focusable so the control is keyboard-+ * reachable. Per-frame pointer state (UIInteraction) is transient — the+ * hit-test system creates it on demand, widgets never insert it.+ */+export function makeWidgetInteractable(+ world: World,+ entity: Entity,+ init: WidgetInteractionInit = {},+): void {+ world.insert(entity, Interactable, {+ enabled: !init.disabled,+ blockRaycast: true,+ raycastTarget: true,+ });+ if (init.focusable ?? true) {+ world.insert(entity, Focusable, { tabIndex: init.tabIndex ?? 0, isFocused: false });+ }+}+export interface UIVisualInit {visualType?: UIVisualType;texture?: number;diff --git a/sdk/src/ui/widgets/list-view.ts b/sdk/src/ui/widgets/list-view.tsindex b07837cba..71f469992 100644--- a/sdk/src/ui/widgets/list-view.ts+++ b/sdk/src/ui/widgets/list-view.ts@@ -14,17 +14,14 @@* a kinetic fling) are handled by the behavior plugin once the viewport is a* hovered raycast target.*/-import { Transform } from '../../component';import type { Entity, Vec2 } from '../../types';import type { World } from '../../world';import { UINode, UIPositionType, type UINodeData } from '../core/ui-node';import { px, auto } from '../core/dimension';import { UIMask, MaskMode } from '../core/ui-mask';-import { Interactable, UIInteraction } from '../input/interactable';-import { uiPlugin } from '../ui-plugin';-import { spawnUIEntity, setUIVisible, type UINodeInit, type UIVisualInit } from './helpers';+import { spawnUIEntity, setUIVisible, makeWidgetInteractable, type UINodeInit, type UIVisualInit } from './helpers';import {type DataSource,@@ -39,6 +36,20 @@ import {import { ListView } from '../collection/list-view';import { ScrollContainer } from '../collection/scroll-container';+/**+ * The per-frame runtime a list view plugs into: the tick registry that drives+ * virtualization and the scroll input hookup. The composed `uiPlugin` (and the+ * granular `uiBehaviorPlugin`) satisfy this — passed explicitly so the factory+ * works against whichever plugin instance owns the app, never a module+ * singleton.+ */+export interface ListViewHost {+ registerListView(list: ListView<unknown>): void;+ unregisterListView(list: ListView<unknown>): void;+ attachScrollContainer(entity: Entity, container: ScrollContainer): void;+ detachScrollContainer(entity: Entity): void;+}+/** A single item type: how to build the entity and how to bind data to it. */export interface ListItemTemplate<T> {/** Create one item entity (use `spawnUIEntity` so it carries a UINode). */@@ -55,6 +66,8 @@ export type ListLayoutSpec =export interface CreateListViewOptions<T> {world: World;+ /** The plugin that ticks virtualization + routes scroll input (`uiPlugin`). */+ host: ListViewHost;parent?: Entity;/** Pixel size of the visible window. Required — scroll math needs it up front. */viewportSize: Vec2;@@ -160,7 +173,7 @@ function placeByInset(world: World, entity: Entity, rect: Rect): void {* list.data.append([newPlayer]); // auto-refreshes*/export function createListView<T>(opts: CreateListViewOptions<T>): ListViewHandle<T> {- const { world, viewportSize } = opts;+ const { world, host, viewportSize } = opts;// 1) Viewport: sized box + Scissor mask + a hovered hit-target (for the wheel).const viewport = spawnUIEntity({@@ -170,8 +183,7 @@ export function createListView<T>(opts: CreateListViewOptions<T>): ListViewHandlvisual: opts.background ?? { color: { r: 0, g: 0, b: 0, a: 0 } },});world.insert(viewport, UIMask, { enabled: true, mode: MaskMode.Scissor });- world.insert(viewport, Interactable, { enabled: true, blockRaycast: true, raycastTarget: true });- world.insert(viewport, UIInteraction, { hovered: false, pressed: false, justPressed: false, justReleased: false });+ makeWidgetInteractable(world, viewport, { focusable: false });// 2) Content: an Absolute frame translated by the scroll offset; items live here.const content = spawnUIEntity({@@ -207,7 +219,7 @@ export function createListView<T>(opts: CreateListViewOptions<T>): ListViewHandlsetVisible: (w, e, v) => setUIVisible(w, e, v),onItemBound: opts.onItemBound,});- uiPlugin.registerListView(view as ListView<unknown>);+ host.registerListView(view as ListView<unknown>);// 6) Scroll model: wheel- and drag-driven by the plugin; onScroll translates// the content frame and pushes the offset into the driver.@@ -226,7 +238,7 @@ export function createListView<T>(opts: CreateListViewOptions<T>): ListViewHandlworld.insert(content, UINode, n);view.setScrollOffset(offset);});- uiPlugin.attachScrollContainer(viewport, scroll);+ host.attachScrollContainer(viewport, scroll);// 7) Keep the scroll range in step with the data count.const offData = data.subscribe?.(() => {@@ -251,8 +263,8 @@ export function createListView<T>(opts: CreateListViewOptions<T>): ListViewHandldisposed = true;offScroll();offData?.();- uiPlugin.unregisterListView(view as ListView<unknown>);- uiPlugin.detachScrollContainer(viewport);+ host.unregisterListView(view as ListView<unknown>);+ host.detachScrollContainer(viewport);scroll.dispose();view.dispose();if (world.valid(viewport)) world.despawn(viewport);diff --git a/sdk/src/ui/widgets/prefabs/Button.esprefab b/sdk/src/ui/widgets/prefabs/Button.esprefabindex 286e57f2e..b7073abd9 100644--- a/sdk/src/ui/widgets/prefabs/Button.esprefab+++ b/sdk/src/ui/widgets/prefabs/Button.esprefab@@ -162,6 +162,13 @@"raycastTarget": true}},+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },{"type": "UIController","data": {@@ -172,7 +179,8 @@"normal","hover","pressed",- "disabled"+ "disabled",+ "focused"],"current": "normal"}@@ -211,6 +219,12 @@"g": 0.22,"b": 0.26,"a": 0.5+ },+ "focused": {+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1}}}@@ -224,7 +238,8 @@"normal": "control","hover": "controlHover","pressed": "controlActive",- "disabled": "control"+ "disabled": "control",+ "focused": "controlHover"}}}diff --git a/sdk/src/ui/widgets/prefabs/Dialog.esprefab b/sdk/src/ui/widgets/prefabs/Dialog.esprefabnew file mode 100644index 000000000..d554151a5--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Dialog.esprefab@@ -0,0 +1,348 @@+{+ "version": "2",+ "name": "Dialog",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Dialog",+ "parent": null,+ "children": [+ "1"+ ],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1,+ "y": 1,+ "z": 1+ },+ "worldPosition": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "display": 0,+ "width": {+ "value": 0,+ "unit": 2+ },+ "height": {+ "value": 0,+ "unit": 2+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": 0,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 0+ },+ "insetTop": {+ "value": 0,+ "unit": 0+ },+ "insetRight": {+ "value": 0,+ "unit": 0+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 0.5+ },+ "uvOffset": {+ "x": 0,+ "y": 0+ },+ "uvScale": {+ "x": 1,+ "y": 1+ },+ "sliceBorder": {+ "x": 0,+ "y": 0,+ "z": 0,+ "w": 0+ },+ "tileSize": {+ "x": 32,+ "y": 32+ },+ "fillMethod": 0,+ "fillOrigin": 0,+ "fillAmount": 1,+ "material": 0,+ "enabled": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "visual": "backdrop"+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "UIDialog",+ "data": {+ "closeOnEscape": true,+ "closeOnBackdrop": true+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Node",+ "parent": "0",+ "children": [],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1,+ "y": 1,+ "z": 1+ },+ "worldPosition": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "display": 0,+ "width": {+ "value": 400,+ "unit": 0+ },+ "height": {+ "value": 300,+ "unit": 0+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": -200,+ "unit": 0+ },+ "marginTop": {+ "value": -150,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 50,+ "unit": 1+ },+ "insetTop": {+ "value": 50,+ "unit": 1+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 2+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 0.16,+ "g": 0.16,+ "b": 0.18,+ "a": 1+ },+ "uvOffset": {+ "x": 0,+ "y": 0+ },+ "uvScale": {+ "x": 1,+ "y": 1+ },+ "sliceBorder": {+ "x": 0,+ "y": 0,+ "z": 0,+ "w": 0+ },+ "tileSize": {+ "x": 32,+ "y": 32+ },+ "fillMethod": 0,+ "fillOrigin": 0,+ "fillAmount": 1,+ "material": 0,+ "enabled": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "visual": "surface"+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Dropdown.esprefab b/sdk/src/ui/widgets/prefabs/Dropdown.esprefabindex 67ab411dc..cc14a154a 100644--- a/sdk/src/ui/widgets/prefabs/Dropdown.esprefab+++ b/sdk/src/ui/widgets/prefabs/Dropdown.esprefab@@ -162,6 +162,13 @@"raycastTarget": true}},+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },{"type": "UIController","data": {diff --git a/sdk/src/ui/widgets/prefabs/Slider.esprefab b/sdk/src/ui/widgets/prefabs/Slider.esprefabindex 9fc07d513..f15fa8f4c 100644--- a/sdk/src/ui/widgets/prefabs/Slider.esprefab+++ b/sdk/src/ui/widgets/prefabs/Slider.esprefab@@ -160,6 +160,32 @@"data": {"visual": "track"}+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },+ {+ "type": "UISlider",+ "data": {+ "min": 0,+ "max": 100,+ "step": 1,+ "value": 50,+ "fill": "2",+ "handle": "1"+ }}],"visible": truediff --git a/sdk/src/ui/widgets/prefabs/TextInput.esprefab b/sdk/src/ui/widgets/prefabs/TextInput.esprefabnew file mode 100644index 000000000..5bdbc5f80--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/TextInput.esprefab@@ -0,0 +1,183 @@+{+ "version": "2",+ "name": "TextInput",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "TextInput",+ "parent": null,+ "children": [],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1,+ "y": 1,+ "z": 1+ },+ "worldPosition": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "UINode",+ "data": {+ "position": 0,+ "display": 0,+ "width": {+ "value": 220,+ "unit": 0+ },+ "height": {+ "value": 32,+ "unit": 0+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": 0,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 2+ },+ "insetTop": {+ "value": 0,+ "unit": 2+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 2+ }+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },+ {+ "type": "TextInput",+ "data": {+ "value": "",+ "placeholder": "Text…",+ "placeholderColor": {+ "r": 0.92,+ "g": 0.92,+ "b": 0.94,+ "a": 0.5+ },+ "fontFamily": "Arial",+ "fontSize": 14,+ "color": {+ "r": 0.92,+ "g": 0.92,+ "b": 0.94,+ "a": 1+ },+ "backgroundColor": {+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1+ },+ "padding": 6,+ "maxLength": 0,+ "multiline": false,+ "password": false,+ "readOnly": false,+ "focused": false,+ "cursorPos": 0,+ "dirty": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "input": {+ "background": "control",+ "text": "text",+ "placeholder": "text"+ }+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Toggle.esprefab b/sdk/src/ui/widgets/prefabs/Toggle.esprefabindex 2a5850cc4..0de409eea 100644--- a/sdk/src/ui/widgets/prefabs/Toggle.esprefab+++ b/sdk/src/ui/widgets/prefabs/Toggle.esprefab@@ -162,6 +162,13 @@"raycastTarget": true}},+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },{"type": "UIController","data": {@@ -172,7 +179,8 @@"normal","hover","pressed",- "disabled"+ "disabled",+ "focused"],"current": "normal"}@@ -211,6 +219,12 @@"g": 0.22,"b": 0.26,"a": 0.5+ },+ "focused": {+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1}}}@@ -224,7 +238,8 @@"normal": "control","hover": "controlHover","pressed": "controlActive",- "disabled": "control"+ "disabled": "control",+ "focused": "controlHover"}}}diff --git a/sdk/src/ui/widgets/prefabs/generated.ts b/sdk/src/ui/widgets/prefabs/generated.tsindex 81cacbaaf..3f4cbb408 100644--- a/sdk/src/ui/widgets/prefabs/generated.ts+++ b/sdk/src/ui/widgets/prefabs/generated.ts@@ -166,6 +166,13 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"raycastTarget": true}},+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },{"type": "UIController","data": {@@ -176,7 +183,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"normal","hover","pressed",- "disabled"+ "disabled",+ "focused"],"current": "normal"}@@ -215,6 +223,12 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"g": 0.22,"b": 0.26,"a": 0.5+ },+ "focused": {+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1}}}@@ -228,7 +242,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"normal": "control","hover": "controlHover","pressed": "controlActive",- "disabled": "control"+ "disabled": "control",+ "focused": "controlHover"}}}@@ -564,6 +579,13 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"raycastTarget": true}},+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },{"type": "UIController","data": {@@ -574,7 +596,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"normal","hover","pressed",- "disabled"+ "disabled",+ "focused"],"current": "normal"}@@ -613,6 +636,12 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"g": 0.22,"b": 0.26,"a": 0.5+ },+ "focused": {+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1}}}@@ -626,7 +655,8 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"normal": "control","hover": "controlHover","pressed": "controlActive",- "disabled": "control"+ "disabled": "control",+ "focused": "controlHover"}}}@@ -955,6 +985,32 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"data": {"visual": "track"}+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },+ {+ "type": "UISlider",+ "data": {+ "min": 0,+ "max": 100,+ "step": 1,+ "value": 50,+ "fill": "2",+ "handle": "1"+ }}],"visible": true@@ -1277,14 +1333,14 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {}]},- "Progress": {+ "Dialog": {"version": "2",- "name": "Progress",+ "name": "Dialog","rootEntityId": "0","entities": [{"prefabEntityId": "0",- "name": "Progress",+ "name": "Dialog","parent": null,"children": ["1"@@ -1330,15 +1386,15 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {{"type": "UINode","data": {- "position": 0,+ "position": 1,"display": 0,"width": {- "value": 200,- "unit": 0+ "value": 0,+ "unit": 2},"height": {- "value": 14,- "unit": 0+ "value": 0,+ "unit": 2},"minWidth": {"value": 0,@@ -1381,19 +1437,19 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {},"insetLeft": {"value": 0,- "unit": 2+ "unit": 0},"insetTop": {"value": 0,- "unit": 2+ "unit": 0},"insetRight": {"value": 0,- "unit": 2+ "unit": 0},"insetBottom": {"value": 0,- "unit": 2+ "unit": 0}}},@@ -1403,10 +1459,10 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"visualType": 1,"texture": 0,"color": {- "r": 0.15,- "g": 0.15,- "b": 0.15,- "a": 1+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 0.5},"uvOffset": {"x": 0,@@ -1436,7 +1492,22 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {{"type": "ThemeStyle","data": {- "visual": "track"+ "visual": "backdrop"+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "UIDialog",+ "data": {+ "closeOnEscape": true,+ "closeOnBackdrop": true}}],@@ -1491,12 +1562,12 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"position": 1,"display": 0,"width": {- "value": 0,- "unit": 2+ "value": 400,+ "unit": 0},"height": {- "value": 0,- "unit": 2+ "value": 300,+ "unit": 0},"minWidth": {"value": 0,@@ -1522,11 +1593,11 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {},"alignSelf": 0,"marginLeft": {- "value": 0,+ "value": -200,"unit": 0},"marginTop": {- "value": 0,+ "value": -150,"unit": 0},"marginRight": {@@ -1538,32 +1609,32 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"unit": 0},"insetLeft": {- "value": 0,- "unit": 0+ "value": 50,+ "unit": 1},"insetTop": {- "value": 0,- "unit": 0+ "value": 50,+ "unit": 1},"insetRight": {"value": 0,- "unit": 0+ "unit": 2},"insetBottom": {"value": 0,- "unit": 0+ "unit": 2}}},{"type": "UIVisual","data": {- "visualType": 5,+ "visualType": 1,"texture": 0,"color": {- "r": 0.25,- "g": 0.56,- "b": 0.96,+ "r": 0.16,+ "g": 0.16,+ "b": 0.18,"a": 1},"uvOffset": {@@ -1586,7 +1657,7 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {},"fillMethod": 0,"fillOrigin": 0,- "fillAmount": 0.4,+ "fillAmount": 1,"material": 0,"enabled": true}@@ -1594,7 +1665,15 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {{"type": "ThemeStyle","data": {- "visual": "primary"+ "visual": "surface"+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true}}],@@ -1602,18 +1681,16 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {}]},- "Dropdown": {+ "TextInput": {"version": "2",- "name": "Dropdown",+ "name": "TextInput","rootEntityId": "0","entities": [{"prefabEntityId": "0",- "name": "Dropdown",+ "name": "TextInput","parent": null,- "children": [- "1"- ],+ "children": [],"components": [{"type": "Transform",@@ -1658,11 +1735,11 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {"position": 0,"display": 0,"width": {- "value": 150,+ "value": 220,"unit": 0},"height": {- "value": 34,+ "value": 32,"unit": 0},"minWidth": {@@ -1723,47 +1800,564 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {}},{- "type": "UIVisual",+ "type": "Interactable","data": {- "visualType": 1,- "texture": 0,+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false+ }+ },+ {+ "type": "TextInput",+ "data": {+ "value": "",+ "placeholder": "Text…",+ "placeholderColor": {+ "r": 0.92,+ "g": 0.92,+ "b": 0.94,+ "a": 0.5+ },+ "fontFamily": "Arial",+ "fontSize": 14,"color": {+ "r": 0.92,+ "g": 0.92,+ "b": 0.94,+ "a": 1+ },+ "backgroundColor": {"r": 0.22,"g": 0.22,"b": 0.26,"a": 1},- "uvOffset": {+ "padding": 6,+ "maxLength": 0,+ "multiline": false,+ "password": false,+ "readOnly": false,+ "focused": false,+ "cursorPos": 0,+ "dirty": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "input": {+ "background": "control",+ "text": "text",+ "placeholder": "text"+ }+ }+ }+ ],+ "visible": true+ }+ ]+ },+ "Progress": {+ "version": "2",+ "name": "Progress",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Progress",+ "parent": null,+ "children": [+ "1"+ ],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {"x": 0,- "y": 0+ "y": 0,+ "z": 0},- "uvScale": {+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {"x": 1,- "y": 1+ "y": 1,+ "z": 1},- "sliceBorder": {+ "worldPosition": {"x": 0,"y": 0,- "z": 0,- "w": 0+ "z": 0},- "tileSize": {- "x": 32,- "y": 32+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0},- "fillMethod": 0,- "fillOrigin": 0,- "fillAmount": 1,- "material": 0,- "enabled": true+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }}},{- "type": "Interactable",+ "type": "UINode","data": {- "enabled": true,- "blockRaycast": true,- "raycastTarget": true+ "position": 0,+ "display": 0,+ "width": {+ "value": 200,+ "unit": 0+ },+ "height": {+ "value": 14,+ "unit": 0+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": 0,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 2+ },+ "insetTop": {+ "value": 0,+ "unit": 2+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 2+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 0.15,+ "g": 0.15,+ "b": 0.15,+ "a": 1+ },+ "uvOffset": {+ "x": 0,+ "y": 0+ },+ "uvScale": {+ "x": 1,+ "y": 1+ },+ "sliceBorder": {+ "x": 0,+ "y": 0,+ "z": 0,+ "w": 0+ },+ "tileSize": {+ "x": 32,+ "y": 32+ },+ "fillMethod": 0,+ "fillOrigin": 0,+ "fillAmount": 1,+ "material": 0,+ "enabled": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "visual": "track"+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Node",+ "parent": "0",+ "children": [],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1,+ "y": 1,+ "z": 1+ },+ "worldPosition": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "UINode",+ "data": {+ "position": 1,+ "display": 0,+ "width": {+ "value": 0,+ "unit": 2+ },+ "height": {+ "value": 0,+ "unit": 2+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": 0,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 0+ },+ "insetTop": {+ "value": 0,+ "unit": 0+ },+ "insetRight": {+ "value": 0,+ "unit": 0+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 5,+ "texture": 0,+ "color": {+ "r": 0.25,+ "g": 0.56,+ "b": 0.96,+ "a": 1+ },+ "uvOffset": {+ "x": 0,+ "y": 0+ },+ "uvScale": {+ "x": 1,+ "y": 1+ },+ "sliceBorder": {+ "x": 0,+ "y": 0,+ "z": 0,+ "w": 0+ },+ "tileSize": {+ "x": 32,+ "y": 32+ },+ "fillMethod": 0,+ "fillOrigin": 0,+ "fillAmount": 0.4,+ "material": 0,+ "enabled": true+ }+ },+ {+ "type": "ThemeStyle",+ "data": {+ "visual": "primary"+ }+ }+ ],+ "visible": true+ }+ ]+ },+ "Dropdown": {+ "version": "2",+ "name": "Dropdown",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Dropdown",+ "parent": null,+ "children": [+ "1"+ ],+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "scale": {+ "x": 1,+ "y": 1,+ "z": 1+ },+ "worldPosition": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldRotation": {+ "w": 1,+ "x": 0,+ "y": 0,+ "z": 0+ },+ "worldScale": {+ "x": 1,+ "y": 1,+ "z": 1+ }+ }+ },+ {+ "type": "UINode",+ "data": {+ "position": 0,+ "display": 0,+ "width": {+ "value": 150,+ "unit": 0+ },+ "height": {+ "value": 34,+ "unit": 0+ },+ "minWidth": {+ "value": 0,+ "unit": 2+ },+ "minHeight": {+ "value": 0,+ "unit": 2+ },+ "maxWidth": {+ "value": 0,+ "unit": 2+ },+ "maxHeight": {+ "value": 0,+ "unit": 2+ },+ "flexGrow": 0,+ "flexShrink": 1,+ "flexBasis": {+ "value": 0,+ "unit": 2+ },+ "alignSelf": 0,+ "marginLeft": {+ "value": 0,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 0,+ "unit": 2+ },+ "insetTop": {+ "value": 0,+ "unit": 2+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 2+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1+ },+ "uvOffset": {+ "x": 0,+ "y": 0+ },+ "uvScale": {+ "x": 1,+ "y": 1+ },+ "sliceBorder": {+ "x": 0,+ "y": 0,+ "z": 0,+ "w": 0+ },+ "tileSize": {+ "x": 32,+ "y": 32+ },+ "fillMethod": 0,+ "fillOrigin": 0,+ "fillAmount": 1,+ "material": 0,+ "enabled": true+ }+ },+ {+ "type": "Interactable",+ "data": {+ "enabled": true,+ "blockRaycast": true,+ "raycastTarget": true+ }+ },+ {+ "type": "Focusable",+ "data": {+ "tabIndex": 0,+ "isFocused": false}},{@@ -2339,4 +2933,4 @@ export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {}};-export const BUILTIN_UI_WIDGET_NAMES = ["Button","Toggle","Slider","Progress","Dropdown","ListView"] as const;+export const BUILTIN_UI_WIDGET_NAMES = ["Button","Toggle","Slider","Dialog","TextInput","Progress","Dropdown","ListView"] as const;diff --git a/sdk/src/ui/widgets/scroll-view.ts b/sdk/src/ui/widgets/scroll-view.tsnew file mode 100644index 000000000..3be132483--- /dev/null+++ b/sdk/src/ui/widgets/scroll-view.ts@@ -0,0 +1,123 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file scroll-view.ts+ * @brief createScrollView — a clipped, scrollable panel for arbitrary content.+ *+ * The non-virtualized sibling of createListView: a Scissor-masked viewport+ * whose content frame is translated by a ScrollContainer (wheel + drag/touch+ * with kinetic fling, driven by the behavior plugin). Parent anything under+ * `content`; sizes are explicit because scroll math needs them up front.+ */+import type { Entity, Vec2 } from '../../types';+import type { World } from '../../world';++import { UINode, UIPositionType, type UINodeData } from '../core/ui-node';+import { px } from '../core/dimension';+import { UIMask, MaskMode } from '../core/ui-mask';+import { ScrollContainer } from '../collection/scroll-container';++import { spawnUIEntity, makeWidgetInteractable, type UINodeInit, type UIVisualInit } from './helpers';+import type { ListViewHost } from './list-view';++export interface ScrollViewOptions {+ world: World;+ /** The plugin that routes scroll input (`uiPlugin`). */+ host: ListViewHost;+ parent?: Entity;+ /** Pixel size of the visible window. */+ viewportSize: Vec2;+ /** Pixel size of the scrollable content frame. */+ contentSize: Vec2;+ /** Extra viewport UINode props (its size defaults to `viewportSize`). */+ node?: UINodeInit;+ /** Viewport background. Default: a transparent hit-target (so the wheel works). */+ background?: UIVisualInit;+ /** Scroll axis. Default 'vertical'. */+ direction?: 'vertical' | 'horizontal' | 'both';+ /** Wheel delta multiplier. Default 1. */+ wheelSpeed?: number;+ /** Drag/touch scrolling with a kinetic fling. Default true. */+ dragScroll?: boolean;+ /** Fling velocity fraction left after 1s of coasting. Default 0.135. */+ decelerationRate?: number;+ onScroll?: (offset: Vec2) => void;+}++export interface ScrollViewHandle {+ /** The viewport entity (the clipped window; add it to your UI tree). */+ readonly entity: Entity;+ /** The scrolling content frame — parent your content here. */+ readonly content: Entity;+ /** The scroll model (escape hatch: `scrollBy`, `onScroll`, …). */+ readonly scroll: ScrollContainer;+ scrollTo(offset: Vec2): void;+ /** Update the scroll range after content changes size. */+ setContentSize(size: Vec2): void;+ dispose(): void;+}++export function createScrollView(opts: ScrollViewOptions): ScrollViewHandle {+ const { world, host, viewportSize, contentSize } = opts;++ const viewport = spawnUIEntity({+ world,+ parent: opts.parent,+ node: { width: px(viewportSize.x), height: px(viewportSize.y), ...opts.node },+ visual: opts.background ?? { color: { r: 0, g: 0, b: 0, a: 0 } },+ });+ world.insert(viewport, UIMask, { enabled: true, mode: MaskMode.Scissor });+ makeWidgetInteractable(world, viewport, { focusable: false });++ const content = spawnUIEntity({+ world,+ parent: viewport,+ node: {+ position: UIPositionType.Absolute,+ insetLeft: px(0),+ insetTop: px(0),+ width: px(contentSize.x),+ height: px(contentSize.y),+ },+ });++ const scroll = new ScrollContainer({+ viewportSize,+ contentSize,+ direction: opts.direction ?? 'vertical',+ wheelSpeed: opts.wheelSpeed,+ dragScroll: opts.dragScroll,+ decelerationRate: opts.decelerationRate,+ });+ const offScroll = scroll.onScroll((offset) => {+ const n = world.get(content, UINode) as UINodeData;+ n.insetLeft = px(-offset.x);+ n.insetTop = px(-offset.y);+ world.insert(content, UINode, n);+ opts.onScroll?.(offset);+ });+ host.attachScrollContainer(viewport, scroll);++ let disposed = false;+ return {+ entity: viewport,+ content,+ scroll,+ scrollTo: (offset) => scroll.setOffset(offset),+ setContentSize: (size) => {+ const n = world.get(content, UINode) as UINodeData;+ n.width = px(size.x);+ n.height = px(size.y);+ world.insert(content, UINode, n);+ scroll.setContentSize(size);+ },+ dispose: () => {+ if (disposed) return;+ disposed = true;+ offScroll();+ host.detachScrollContainer(viewport);+ scroll.dispose();+ if (world.valid(viewport)) world.despawn(viewport);+ },+ };+}diff --git a/sdk/src/ui/widgets/slider.ts b/sdk/src/ui/widgets/slider.tsindex cb5853e4f..7d329d1b1 100644--- a/sdk/src/ui/widgets/slider.ts+++ b/sdk/src/ui/widgets/slider.ts@@ -3,27 +3,35 @@import type { Entity } from '../../types';import type { World } from '../../world';-import { UINode, type UINodeData } from '../core/ui-node';import { px, percent } from '../core/dimension';-import { UIVisual, UIVisualType, type UIVisualData } from '../core/ui-visual';+import { UIVisualType } from '../core/ui-visual';+import { UIEventType, type UIEventQueue } from '../core/events';-import { spawnUIEntity, FILL_AXIS, type UINodeInit, type UIVisualInit } from './helpers';+import { spawnUIEntity, makeWidgetInteractable, FILL_AXIS, type UINodeInit, type UIVisualInit } from './helpers';import { themeColors } from '../theme/tokens';import { markThemed } from '../theme/theme-style';+import { UISlider, sliderClamp, sliderFraction, type UISliderData } from '../behavior/slider';export interface SliderOptions {world: World;+ events: UIEventQueue;parent?: Entity;node?: UINodeInit;min?: number;max?: number;value?: number;/**- * Optional quantization step. `0` (default) = continuous.+ * Optional quantization step. `0` (default) = continuous. Also the+ * keyboard nudge; a continuous slider nudges by 1% of the range.*/step?: number;/** Handle width in pixels. Default 12. */handleWidth?: number;+ /** Start disabled. */+ disabled?: boolean;+ /** Participate in Tab traversal + arrow-key nudging. Default true. */+ focusable?: boolean;+ tabIndex?: number;trackVisual?: UIVisualInit;fillVisual?: UIVisualInit;@@ -39,27 +47,24 @@ export interface SliderHandle {readonly handleEntity: Entity;getValue(): number;setValue(value: number): void;- /**- * Translate a track-local x position (pixels from left) to a slider- * value, clamped and optionally snapped to `step`. Caller wires- * this to their drag / click handlers — v1 has no built-in input.- */- valueAtLocalX(localX: number, trackWidth: number): number;dispose(): void;}/*** Horizontal slider composed of a track, a fill bar, and a handle thumb.- * Interaction (drag, click-to-snap) is not wired here — use- * `valueAtLocalX()` with your own pointer handler, or call `setValue`- * directly.+ * State + input live in the {@link UISlider} component and its behavior+ * system: pointer drag (press-capture on the track), arrow keys / Home / End+ * while focused, and value→visual sync for any writer — this handle, a+ * binding, or the editor inspector.*/export function createSlider(opts: SliderOptions): SliderHandle {+ const { world, events } = opts;const min = opts.min ?? 0;const max = opts.max ?? 1;const step = opts.step ?? 0;const handleWidth = opts.handleWidth ?? 12;- let value = clampAndSnap(opts.value ?? min, min, max, step);+ const value = sliderClamp(opts.value ?? min, { min, max, step });+ const frac = sliderFraction({ min, max, value });const c = themeColors();@@ -68,81 +73,69 @@ export function createSlider(opts: SliderOptions): SliderHandle {const [fillMethod, fillOrigin] = FILL_AXIS.right;const track = spawnUIEntity({- world: opts.world,+ world,parent: opts.parent,node: opts.node ?? { fill: true },visual: opts.trackVisual ?? { color: c.track },});- if (!opts.trackVisual) markThemed(opts.world, track, { visual: 'track' });+ if (!opts.trackVisual) markThemed(world, track, { visual: 'track' });+ makeWidgetInteractable(world, track, {+ disabled: opts.disabled,+ focusable: opts.focusable,+ tabIndex: opts.tabIndex,+ });const fill = spawnUIEntity({- world: opts.world,+ world,parent: track,node: { fill: true },visual: {visualType: UIVisualType.Filled,fillMethod,fillOrigin,- fillAmount: fraction(value, min, max),+ fillAmount: frac,...(opts.fillVisual ?? { color: c.primary }),},});- if (!opts.fillVisual) markThemed(opts.world, fill, { visual: 'primary' });+ if (!opts.fillVisual) markThemed(world, fill, { visual: 'primary' });const handle = spawnUIEntity({- world: opts.world,+ world,parent: track,- node: handleNodeAt(fraction(value, min, max), handleWidth),+ node: handleNodeAt(frac, handleWidth),visual: opts.handleVisual ?? { color: c.onPrimary },});- if (!opts.handleVisual) markThemed(opts.world, handle, { visual: 'onPrimary' });-- // Value -> visuals: the fill's Filled amount is the value fraction (a- // render-time crop, no relayout); the handle's left inset tracks it,- // centered via a -half-width margin.- function writeVisuals(t: number): void {- const vis = opts.world.get(fill, UIVisual) as UIVisualData;- vis.fillAmount = t;- opts.world.insert(fill, UIVisual, vis);-- const handleNode = opts.world.get(handle, UINode) as UINodeData;- handleNode.insetLeft = percent(t * 100);- opts.world.insert(handle, UINode, handleNode);- }-- function setValue(next: number): void {- const v = clampAndSnap(next, min, max, step);- if (v === value) return;- value = v;- writeVisuals(fraction(value, min, max));- opts.onChange?.(value, track);- }-- function valueAtLocalX(localX: number, trackWidth: number): number {- if (trackWidth <= 0) return min;- const t = clamp(localX / trackWidth, 0, 1);- return clampAndSnap(min + t * (max - min), min, max, step);- }+ if (!opts.handleVisual) markThemed(world, handle, { visual: 'onPrimary' });++ world.insert(track, UISlider, { min, max, step, value, fill, handle });++ const offChange = opts.onChange+ ? events.on(track, UIEventType.Change, (ev) => {+ opts.onChange!((ev.data as { value: number }).value, track);+ })+ : undefined;return {entity: track,trackEntity: track,fillEntity: fill,handleEntity: handle,- getValue: () => value,- setValue,- valueAtLocalX,+ getValue: () => (world.get(track, UISlider) as UISliderData).value,+ setValue: (next: number) => {+ const d = world.get(track, UISlider) as UISliderData;+ const v = sliderClamp(next, d);+ if (v !== d.value) {+ d.value = v;+ world.insert(track, UISlider, d);+ }+ },dispose: () => {- if (opts.world.valid(track)) opts.world.despawn(track);+ offChange?.();+ if (world.valid(track)) world.despawn(track);},};}-function fraction(value: number, min: number, max: number): number {- if (max <= min) return 0;- return clamp((value - min) / (max - min), 0, 1);-}-// Handle: absolute, full height, fixed width, centered at the value fraction// (left inset = t%, shifted left by half its width).function handleNodeAt(t: number, width: number): UINodeInit {@@ -155,14 +148,3 @@ function handleNodeAt(t: number, width: number): UINodeInit {width: px(width),};}--function clamp(value: number, lo: number, hi: number): number {- return value < lo ? lo : value > hi ? hi : value;-}--function clampAndSnap(value: number, min: number, max: number, step: number): number {- const clamped = clamp(value, min, max);- if (step <= 0) return clamped;- const snapped = Math.round((clamped - min) / step) * step + min;- return clamp(snapped, min, max);-}diff --git a/sdk/src/ui/widgets/text-input.ts b/sdk/src/ui/widgets/text-input.tsnew file mode 100644index 000000000..a23e84b07--- /dev/null+++ b/sdk/src/ui/widgets/text-input.ts@@ -0,0 +1,125 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import type { Color, Entity } from '../../types';+import type { World } from '../../world';++import { px } from '../core/dimension';+import { type UIEventQueue } from '../core/events';+import { TextInput, type TextInputData } from '../text/text-input';++import { spawnUIEntity, makeWidgetInteractable, type UINodeInit } from './helpers';+import { themeColors, themeType } from '../theme/tokens';+import { markThemed } from '../theme/theme-style';++export interface TextInputOptions {+ world: World;+ events: UIEventQueue;+ parent?: Entity;+ /** CSS-box layout. Default: 220×32. */+ node?: UINodeInit;++ value?: string;+ placeholder?: string;+ fontFamily?: string;+ /** Default: the theme's label size. */+ fontSize?: number;+ /** 0 = unlimited. */+ maxLength?: number;+ password?: boolean;+ multiline?: boolean;+ readOnly?: boolean;+ /** Inner horizontal padding in px. Default 6. */+ padding?: number;++ /** Text / background / placeholder color overrides (theme roles otherwise). */+ color?: Color;+ backgroundColor?: Color;+ placeholderColor?: Color;++ disabled?: boolean;+ tabIndex?: number;++ /** Fires on every edit. */+ onChange?: (value: string, entity: Entity) => void;+ /** Fires on Enter (single-line). */+ onSubmit?: (value: string, entity: Entity) => void;+}++export interface TextInputHandle {+ readonly entity: Entity;+ getValue(): string;+ setValue(value: string): void;+ dispose(): void;+}++/**+ * Single-call editable text field over the {@link TextInput} component and its+ * SDF input plugin (focus, caret, IME gate, clipboard, password masking).+ * Colors default to theme roles and re-resolve on `switchTheme`.+ */+export function createTextInput(opts: TextInputOptions): TextInputHandle {+ const { world, events } = opts;+ const c = themeColors();++ const entity = spawnUIEntity({+ world,+ parent: opts.parent,+ node: opts.node ?? { width: px(220), height: px(32) },+ });+ // Text fields are always focusable — that is what they are for.+ makeWidgetInteractable(world, entity, { disabled: opts.disabled, tabIndex: opts.tabIndex });++ world.insert(entity, TextInput, {+ value: opts.value ?? '',+ placeholder: opts.placeholder ?? '',+ placeholderColor: opts.placeholderColor ?? { ...c.text, a: c.text.a * 0.5 },+ fontFamily: opts.fontFamily ?? 'Arial',+ fontSize: opts.fontSize ?? themeType().label,+ color: opts.color ?? { ...c.text },+ backgroundColor: opts.backgroundColor ?? { ...c.control },+ padding: opts.padding ?? 6,+ maxLength: opts.maxLength ?? 0,+ multiline: opts.multiline ?? false,+ password: opts.password ?? false,+ readOnly: opts.readOnly ?? false,+ focused: false,+ cursorPos: (opts.value ?? '').length,+ dirty: true,+ });+ markThemed(world, entity, {+ input: {+ background: opts.backgroundColor === undefined ? 'control' : undefined,+ text: opts.color === undefined ? 'text' : undefined,+ placeholder: opts.placeholderColor === undefined ? 'text' : undefined,+ },+ });++ const offChange = opts.onChange+ ? events.on(entity, 'change', () => {+ opts.onChange!((world.get(entity, TextInput) as TextInputData).value, entity);+ })+ : undefined;+ const offSubmit = opts.onSubmit+ ? events.on(entity, 'submit', () => {+ opts.onSubmit!((world.get(entity, TextInput) as TextInputData).value, entity);+ })+ : undefined;++ return {+ entity,+ getValue: () => (world.get(entity, TextInput) as TextInputData).value,+ setValue: (value: string) => {+ const ti = world.get(entity, TextInput) as TextInputData;+ if (ti.value === value) return;+ ti.value = value;+ ti.cursorPos = Math.min(ti.cursorPos, value.length);+ ti.dirty = true;+ world.insert(entity, TextInput, ti);+ },+ dispose: () => {+ offChange?.();+ offSubmit?.();+ if (world.valid(entity)) world.despawn(entity);+ },+ };+}diff --git a/sdk/src/ui/widgets/toggle.ts b/sdk/src/ui/widgets/toggle.tsindex bd137585a..f5ca6b769 100644--- a/sdk/src/ui/widgets/toggle.ts+++ b/sdk/src/ui/widgets/toggle.ts@@ -39,6 +39,9 @@ export interface ToggleOptions {isOn?: boolean;/** Start disabled. */disabled?: boolean;+ /** Participate in Tab traversal + Enter/Space activation. Default true. */+ focusable?: boolean;+ tabIndex?: number;onChange?: (isOn: boolean, entity: Entity) => void;}@@ -47,6 +50,7 @@ export interface ToggleHandle {readonly entity: Entity;isOn(): boolean;setIsOn(value: boolean, silent?: boolean): void;+ setDisabled(disabled: boolean): void;dispose(): void;}@@ -59,7 +63,7 @@ export function createToggle(opts: ToggleOptions): ToggleHandle {const { world, events } = opts;let isOn = opts.isOn ?? false;- const button = createButton({+ const btn = createButton({world,events,parent: opts.parent,@@ -67,7 +71,10 @@ export function createToggle(opts: ToggleOptions): ToggleHandle {background: opts.background,states: opts.interactionStates,disabled: opts.disabled,+ focusable: opts.focusable,+ tabIndex: opts.tabIndex,});+ const button = btn.entity;// The on-state indicator defaults to the theme accent so it re-themes live;// a caller-supplied color is the caller's own.@@ -104,9 +111,10 @@ export function createToggle(opts: ToggleOptions): ToggleHandle {entity: button,isOn: () => isOn,setIsOn,+ setDisabled: btn.setDisabled,dispose: () => {offClick();- if (world.valid(button)) world.despawn(button);+ btn.dispose();},};}diff --git a/sdk/tests/ui-list-view-widget.test.ts b/sdk/tests/ui-list-view-widget.test.tsindex 9d901bcf4..72ec4735a 100644--- a/sdk/tests/ui-list-view-widget.test.ts+++ b/sdk/tests/ui-list-view-widget.test.ts@@ -57,6 +57,7 @@ describe.skipIf(!HAS_WASM)('createListView (WASM integration)', () => {it('virtualizes: a 1000-item list mounts only items near the viewport', async () => {const { app, registry } = createApp();const list = createListView<number>({+ host: uiPlugin,world: app.world,viewportSize: { x: 200, y: 200 }, // 5 rows visible @ 40pxdata: bigList(1000),@@ -77,6 +78,7 @@ describe.skipIf(!HAS_WASM)('createListView (WASM integration)', () => {it('re-mounts a new window on scroll without growing the mount set', async () => {const { app, registry } = createApp();const list = createListView<number>({+ host: uiPlugin,world: app.world,viewportSize: { x: 200, y: 200 },data: bigList(1000),@@ -101,6 +103,7 @@ describe.skipIf(!HAS_WASM)('createListView (WASM integration)', () => {const { app, registry } = createApp();const data = bigList(3);const list = createListView<number>({+ host: uiPlugin,world: app.world,viewportSize: { x: 200, y: 400 }, // fits ~10 rows → all 3 visibledata,@@ -123,6 +126,7 @@ describe.skipIf(!HAS_WASM)('createListView (WASM integration)', () => {it('grid layout mounts a virtualized subset of a large tile set', async () => {const { app, registry } = createApp();const list = createListView<number>({+ host: uiPlugin,world: app.world,viewportSize: { x: 300, y: 200 },data: bigList(1000),diff --git a/sdk/tests/ui-slider-dropdown.test.ts b/sdk/tests/ui-slider-dropdown.test.tsindex c4bc76ac5..2b319303f 100644--- a/sdk/tests/ui-slider-dropdown.test.ts+++ b/sdk/tests/ui-slider-dropdown.test.ts@@ -3,6 +3,9 @@import { describe, it, expect, beforeEach, vi } from 'vitest';import {createSlider,+ createSliderSystem,+ UISlider,+ Focusable,createDropdown,UIEventQueue,UIEventType,@@ -27,6 +30,7 @@ interface MockWorld {has(e: Entity, c: object): boolean;get(e: Entity, c: object): unknown;insert(e: Entity, c: object, data: unknown): void;+ getEntitiesWithComponents(cs: object[]): Entity[];onDespawn(cb: (e: Entity) => void): () => void;}@@ -50,6 +54,10 @@ function createMockWorld(): MockWorld {has(e, c) { return w._components.get(e as number)?.has(c) ?? false; },get(e, c) { return w._components.get(e as number)?.get(c); },insert(e, c, d) { w._components.get(e as number)?.set(c, d); },+ getEntitiesWithComponents(cs: object[]) {+ return [...w._entities].filter((e) =>+ cs.every((c) => w._components.get(e)?.has(c))) as Entity[];+ },onDespawn(cb) {w._despawnListeners.push(cb);return () => {@@ -63,33 +71,42 @@ function createMockWorld(): MockWorld {describe('createSlider', () => {let world: MockWorld;+ let events: UIEventQueue;+ let keys: Set<string>;+ let tick: () => void;beforeEach(() => {world = createMockWorld();+ events = new UIEventQueue();+ keys = new Set();+ const sys = createSliderSystem(world as unknown as World, events);+ const input = {+ isMouseButtonDown: () => false,+ isKeyPressed: (k: string) => keys.has(k),+ };+ const camera = { valid: false };+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ tick = () => (sys as any)._fn(input, camera);});+ const make = (opts: Record<string, unknown> = {}) =>+ createSlider({ world: world as unknown as World, events, ...opts });+it('initializes at the provided value, clamped to [min, max]', () => {- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 10, value: 5,- });+ const slider = make({ min: 0, max: 10, value: 5 });expect(slider.getValue()).toBe(5);- const clipped = createSlider({- world: world as unknown as World,- min: 0, max: 10, value: 99,- });+ const clipped = make({ min: 0, max: 10, value: 99 });expect(clipped.getValue()).toBe(10);});- it('setValue clamps and triggers onChange', () => {+ it('setValue clamps, syncs visuals through the system, and fires onChange', () => {const onChange = vi.fn();- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 1, value: 0,- onChange,- });+ const slider = make({ min: 0, max: 1, value: 0, onChange });+ tick(); // initial paint — must not fire a change+slider.setValue(0.5);+ tick();expect(slider.getValue()).toBe(0.5);expect(onChange).toHaveBeenCalledWith(0.5, slider.entity);@@ -98,10 +115,7 @@ describe('createSlider', () => {});it('setValue with step snaps to the nearest step', () => {- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 10, step: 2, value: 0,- });+ const slider = make({ min: 0, max: 10, step: 2, value: 0 });slider.setValue(3); // nearest 2-step → 2 or 4 (round half up in JS → 4)expect([2, 4]).toContain(slider.getValue());@@ -111,52 +125,71 @@ describe('createSlider', () => {it('setValue does not fire onChange when value is unchanged', () => {const onChange = vi.fn();- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 1, value: 0.5, onChange,- });+ const slider = make({ min: 0, max: 1, value: 0.5, onChange });+ tick();slider.setValue(0.5);+ tick();expect(onChange).not.toHaveBeenCalled();});- it('updates fill amount (Filled crop) on setValue', () => {- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 1, value: 0,- });+ it('updates fill amount (Filled crop) through the system', () => {+ const slider = make({ min: 0, max: 1, value: 0 });slider.setValue(0.25);+ tick();const vis = world.get(slider.fillEntity, UIVisual) as { fillAmount: number };expect(vis.fillAmount).toBe(0.25);});- it('updates handle left inset (percent) to position it at t', () => {- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 1, value: 0,- });+ it('updates handle left inset (percent) through the system', () => {+ const slider = make({ min: 0, max: 1, value: 0 });slider.setValue(0.5);+ tick();const node = world.get(slider.handleEntity, UINode) as {insetLeft: { value: number; unit: number };};expect(node.insetLeft).toEqual({ value: 50, unit: DimensionUnit.Percent });});- it('valueAtLocalX maps pointer X to value (with clamping)', () => {- const slider = createSlider({- world: world as unknown as World,- min: 0, max: 100,- });- expect(slider.valueAtLocalX(0, 200)).toBe(0);- expect(slider.valueAtLocalX(100, 200)).toBe(50);- expect(slider.valueAtLocalX(200, 200)).toBe(100);- expect(slider.valueAtLocalX(-50, 200)).toBe(0);- expect(slider.valueAtLocalX(1000, 200)).toBe(100);+ it('arrow keys nudge the focused slider (1% of range when continuous)', () => {+ const onChange = vi.fn();+ const slider = make({ min: 0, max: 100, value: 50, onChange });+ tick();++ const f = world.get(slider.entity, Focusable) as { isFocused: boolean };+ f.isFocused = true;+ world.insert(slider.entity, Focusable, f);++ keys.add('ArrowRight');+ tick();+ expect(slider.getValue()).toBe(51);+ expect(onChange).toHaveBeenCalledWith(51, slider.entity);++ keys.clear();+ keys.add('Home');+ tick();+ expect(slider.getValue()).toBe(0);+ });++ it('ignores input while disabled', () => {+ const slider = make({ min: 0, max: 100, value: 50, disabled: true });+ tick();+ const f = world.get(slider.entity, Focusable) as { isFocused: boolean };+ f.isFocused = true;+ world.insert(slider.entity, Focusable, f);+ keys.add('ArrowRight');+ tick();+ expect(slider.getValue()).toBe(50);+ });++ it('carries the UISlider component with fill/handle refs', () => {+ const slider = make({ min: 0, max: 10, value: 5 });+ const d = world.get(slider.entity, UISlider) as { fill: number; handle: number };+ expect(d.fill).toBe(slider.fillEntity);+ expect(d.handle).toBe(slider.handleEntity);});it('dispose despawns the track root', () => {- const slider = createSlider({- world: world as unknown as World,- });+ const slider = make({});expect(world.valid(slider.entity)).toBe(true);slider.dispose();expect(world.valid(slider.entity)).toBe(false);diff --git a/sdk/tests/ui-theme-swap.test.ts b/sdk/tests/ui-theme-swap.test.tsindex bae7ef001..bf73958df 100644--- a/sdk/tests/ui-theme-swap.test.ts+++ b/sdk/tests/ui-theme-swap.test.ts@@ -81,7 +81,7 @@ describe('live re-theming', () => {it('switchTheme restyles an already-built button (gear pages + label)', () => {const w = mockWorld();- const btn = createButton({ world: w, events: noEvents, text: 'OK' });+ const { entity: btn } = createButton({ world: w, events: noEvents, text: 'OK' });// Built under the default dark theme.expect((colorPages(w, btn).normal as { r: number }).r).toBeCloseTo(DARK_TOKENS.colors.control.r);@@ -98,7 +98,7 @@ describe('live re-theming', () => {it('does not clobber a button whose states the caller supplied', () => {const w = mockWorld();- const btn = createButton({+ const { entity: btn } = createButton({world: w, events: noEvents,states: { normal: { color: { r: 0.5, g: 0.1, b: 0.9, a: 1 } } },});diff --git a/sdk/tests/ui-widget-prefabs.gen.test.ts b/sdk/tests/ui-widget-prefabs.gen.test.tsindex 2c2d52c38..5f660764c 100644--- a/sdk/tests/ui-widget-prefabs.gen.test.ts+++ b/sdk/tests/ui-widget-prefabs.gen.test.ts@@ -12,6 +12,10 @@ import { createToggle } from '../src/ui/widgets/toggle';import { createSlider } from '../src/ui/widgets/slider';import { createProgress } from '../src/ui/widgets/progress';import { createDropdown } from '../src/ui/widgets/dropdown';+import { createDialog } from '../src/ui/widgets/dialog';+import { createTextInput } from '../src/ui/widgets/text-input';+import { UISlider } from '../src/ui/behavior/slider';+import { registerComponent } from '../src/component';import { spawnUIEntity } from '../src/ui/widgets/helpers';import { UIMask, MaskMode } from '../src/ui/core/ui-mask';import { Interactable } from '../src/ui/input/interactable';@@ -61,12 +65,12 @@ describe('UI widget prefab codegen', () => {world, events: noEvents,node: { width: px(140), height: px(40) },text: { content: 'Button', fontSize: 14 },- }) as unknown as number,+ }).entity as unknown as number,);const root = typesOf(prefab, prefab.rootEntityId);expect(root).toEqual(expect.arrayContaining([- 'Transform', 'UINode', 'UIVisual', 'Interactable', 'UIController', 'UIGear',+ 'Transform', 'UINode', 'UIVisual', 'Interactable', 'Focusable', 'UIController', 'UIGear',]));const rootEnt = entityById(prefab, prefab.rootEntityId);expect(rootEnt.children.length).toBe(1);@@ -88,13 +92,53 @@ describe('UI widget prefab codegen', () => {});it('Slider: track + fill + handle', () => {+ // The suite-wide beforeEach clears user components; capture-side entity+ // ref remapping resolves UISlider by name, so put it back (the behavior+ // plugin does this in a real app).+ registerComponent('UISlider', UISlider);const prefab = generate('Slider', (world) =>createSlider({- world, node: { width: px(200), height: px(18) },+ world, events: noEvents, node: { width: px(200), height: px(18) },min: 0, max: 100, step: 1, value: 50, handleWidth: 14,}).entity as unknown as number,);expect(entityById(prefab, prefab.rootEntityId).children.length).toBe(2);+ // The behavior component rides along, with its intra-prefab entity refs+ // remapped to prefab-local ids — an editor-placed slider is functional.+ const sliderComp = entityById(prefab, prefab.rootEntityId).components+ .find((cc) => cc.type === 'UISlider')!;+ expect(sliderComp).toBeDefined();+ const kids = entityById(prefab, prefab.rootEntityId).children;+ expect(kids).toContain(sliderComp.data.fill);+ expect(kids).toContain(sliderComp.data.handle);+ });++ it('Dialog: backdrop scrim + panel, dismissal data-driven by UIDialog', () => {+ const prefab = generate('Dialog', (world) =>+ createDialog({+ world, events: noEvents,+ startHidden: false, // an editor-placed dialog should be visible+ }).entity as unknown as number,+ );+ expect(typesOf(prefab, prefab.rootEntityId)).toEqual(expect.arrayContaining([+ 'UINode', 'UIVisual', 'Interactable', 'UIDialog',+ ]));+ const rootEnt = entityById(prefab, prefab.rootEntityId);+ expect(rootEnt.children.length).toBe(1);+ expect(typesOf(prefab, rootEnt.children[0]!)).toEqual(+ expect.arrayContaining(['UINode', 'UIVisual', 'Interactable']));+ });++ it('TextInput: an editable field over the SDF input plugin', () => {+ const prefab = generate('TextInput', (world) =>+ createTextInput({+ world, events: noEvents,+ placeholder: 'Text…',+ }).entity as unknown as number,+ );+ expect(typesOf(prefab, prefab.rootEntityId)).toEqual(expect.arrayContaining([+ 'UINode', 'Interactable', 'Focusable', 'TextInput', 'ThemeStyle',+ ]));});it('Progress: track + fill', () => {diff --git a/sdk/tests/ui-widgets.test.ts b/sdk/tests/ui-widgets.test.tsindex 85c07feca..3f311633c 100644--- a/sdk/tests/ui-widgets.test.ts+++ b/sdk/tests/ui-widgets.test.ts@@ -20,6 +20,7 @@ import {UIEventQueue,UIEventType,UIDisplay,+ UIDialog,themeColors,type UIControllerData,type UIGearData,@@ -108,7 +109,7 @@ describe('createButton', () => {.find((c) => c.name === INTERACTION_CONTROLLER)!;it('attaches the required components', () => {- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,states: {@@ -127,7 +128,7 @@ describe('createButton', () => {});it('folds the `states` map into a $interaction color gear', () => {- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,states: {@@ -148,7 +149,7 @@ describe('createButton', () => {});it('defaults its states to the active theme control roles (de-nude)', () => {- const btn = createButton({ world: world as unknown as World, events, text: 'OK' });+ const { entity: btn } = createButton({ world: world as unknown as World, events, text: 'OK' });const gear = world.get(btn, UIGear) as UIGearData;const colorGear = gear.bindings.find((b) => b.property === 'color')!;const c = themeColors();@@ -159,7 +160,7 @@ describe('createButton', () => {});it('starts on the "disabled" page when opts.disabled is true', () => {- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,disabled: true,@@ -174,19 +175,19 @@ describe('createButton', () => {});it('lists canonical pages first, then custom states', () => {- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,states: { normal: {}, loading: {}, celebrating: {} },});expect(interactionOf(btn).pages).toEqual(- ['normal', 'hover', 'pressed', 'disabled', 'loading', 'celebrating'],+ ['normal', 'hover', 'pressed', 'disabled', 'focused', 'loading', 'celebrating'],);});it('fires onClick on the interaction layer click event', () => {const onClick = vi.fn();- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,states: { normal: {}, hover: {}, pressed: {} },@@ -199,7 +200,7 @@ describe('createButton', () => {it('swallows clicks while disabled', () => {const onClick = vi.fn();- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,disabled: true,@@ -212,7 +213,7 @@ describe('createButton', () => {});it('setButtonState writes the $interaction page, growing the enum for custom states', () => {- const btn = createButton({+ const { entity: btn } = createButton({world: world as unknown as World,events,states: { normal: {} },@@ -408,45 +409,59 @@ describe('createProgress', () => {describe('createDialog', () => {let world: MockWorld;+ let events: UIEventQueue;beforeEach(() => {world = createMockWorld();+ events = new UIEventQueue();});it('starts hidden by default — backdrop subtree is display:none', () => {- const dialog = createDialog({ world: world as unknown as World });+ const dialog = createDialog({ world: world as unknown as World, events });expect(dialog.isOpen()).toBe(false);- const bg = world.get(dialog.backdropEntity, UINode) as { display: number };+ const bg = world.get(dialog.entity, UINode) as { display: number };expect(bg.display).toBe(UIDisplay.None);});it('open() restores display:flex on the backdrop root', () => {- const dialog = createDialog({ world: world as unknown as World });+ const dialog = createDialog({ world: world as unknown as World, events });dialog.open();expect(dialog.isOpen()).toBe(true);- const bg = world.get(dialog.backdropEntity, UINode) as { display: number };+ const bg = world.get(dialog.entity, UINode) as { display: number };expect(bg.display).toBe(UIDisplay.Flex);// The blocker stays enabled permanently — display:none already removes// the whole subtree from hit-testing while closed.- const inter = world.get(dialog.backdropEntity, Interactable) as { enabled: boolean };+ const inter = world.get(dialog.entity, Interactable) as { enabled: boolean };expect(inter.enabled).toBe(true);});it('close() sets display:none so user children under the panel vanish too', () => {- const dialog = createDialog({ world: world as unknown as World, startHidden: false });+ const dialog = createDialog({ world: world as unknown as World, events, startHidden: false });expect(dialog.isOpen()).toBe(true);dialog.close();expect(dialog.isOpen()).toBe(false);- const bg = world.get(dialog.backdropEntity, UINode) as { display: number };+ const bg = world.get(dialog.entity, UINode) as { display: number };expect(bg.display).toBe(UIDisplay.None);});+ it('open/close carry the dismissal component and report through onOpenChange', () => {+ const seen: boolean[] = [];+ const dialog = createDialog({+ world: world as unknown as World, events,+ onOpenChange: (open) => seen.push(open),+ });+ expect(world.has(dialog.entity, UIDialog)).toBe(true);+ dialog.open();+ dialog.close();+ expect(seen).toEqual([true, false]);+ });+it('dispose despawns the backdrop', () => {- const dialog = createDialog({ world: world as unknown as World });- expect(world.valid(dialog.backdropEntity)).toBe(true);+ const dialog = createDialog({ world: world as unknown as World, events });+ expect(world.valid(dialog.entity)).toBe(true);dialog.dispose();- expect(world.valid(dialog.backdropEntity)).toBe(false);+ expect(world.valid(dialog.entity)).toBe(false);});});