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): generate built-in widget prefabs from the factories
yhh467717dcb26f
diff --git a/sdk/src/core-ui.ts b/sdk/src/core-ui.tsindex 155ecabbe..7494949ac 100644--- a/sdk/src/core-ui.ts+++ b/sdk/src/core-ui.ts@@ -141,4 +141,7 @@ export {createDropdown,type DropdownOptions,type DropdownHandle,+ widgetToPrefab,+ BUILTIN_UI_PREFABS,+ BUILTIN_UI_WIDGET_NAMES,} from './ui';diff --git a/sdk/src/ui/index.ts b/sdk/src/ui/index.tsindex 96259bccf..c09cada6c 100644--- a/sdk/src/ui/index.ts+++ b/sdk/src/ui/index.ts@@ -229,6 +229,9 @@ export {type DropdownHandle,} from './widgets/dropdown';+export { widgetToPrefab } from './widgets/toPrefab';+export { BUILTIN_UI_PREFABS, BUILTIN_UI_WIDGET_NAMES } from './widgets/prefabs/generated';+// ─── Rendering / text helpers ───────────────────────────────────────────────// All text — display (Text) and editable (TextInput) — now renders through thediff --git a/sdk/src/ui/widgets/prefabs/Button.esprefab b/sdk/src/ui/widgets/prefabs/Button.esprefabnew file mode 100644index 000000000..222d2a1c3--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Button.esprefab@@ -0,0 +1,374 @@+{+ "version": "2",+ "name": "Button",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Button",+ "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,+ "width": {+ "value": 140,+ "unit": 0+ },+ "height": {+ "value": 40,+ "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": 1,+ "g": 1,+ "b": 1,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Label",+ "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,+ "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": "Text",+ "data": {+ "content": "Button",+ "fontFamily": "Arial",+ "fontSize": 14,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "align": 1,+ "verticalAlign": 1,+ "wordWrap": false,+ "overflow": 0,+ "lineHeight": 1.2,+ "bold": false,+ "italic": false,+ "strokeColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "strokeWidth": 0,+ "shadowColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "shadowBlur": 0,+ "shadowOffsetX": 0,+ "shadowOffsetY": 0,+ "richText": false+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Dropdown.esprefab b/sdk/src/ui/widgets/prefabs/Dropdown.esprefabnew file mode 100644index 000000000..66ce35657--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Dropdown.esprefab@@ -0,0 +1,374 @@+{+ "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,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Label",+ "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,+ "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": "Text",+ "data": {+ "content": "One",+ "fontFamily": "Arial",+ "fontSize": 14,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "align": 1,+ "verticalAlign": 1,+ "wordWrap": false,+ "overflow": 0,+ "lineHeight": 1.2,+ "bold": false,+ "italic": false,+ "strokeColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "strokeWidth": 0,+ "shadowColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "shadowBlur": 0,+ "shadowOffsetX": 0,+ "shadowOffsetY": 0,+ "richText": false+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Progress.esprefab b/sdk/src/ui/widgets/prefabs/Progress.esprefabnew file mode 100644index 000000000..3fc6419b9--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Progress.esprefab@@ -0,0 +1,311 @@+{+ "version": "2",+ "name": "Progress",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Progress",+ "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,+ "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+ }+ }+ ],+ "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,+ "width": {+ "value": 40,+ "unit": 1+ },+ "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": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Slider.esprefab b/sdk/src/ui/widgets/prefabs/Slider.esprefabnew file mode 100644index 000000000..c41850136--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Slider.esprefab@@ -0,0 +1,463 @@+{+ "version": "2",+ "name": "Slider",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Slider",+ "parent": null,+ "children": [+ "2",+ "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,+ "width": {+ "value": 200,+ "unit": 0+ },+ "height": {+ "value": 18,+ "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+ }+ }+ ],+ "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,+ "width": {+ "value": 14,+ "unit": 0+ },+ "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": -7,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 50,+ "unit": 1+ },+ "insetTop": {+ "value": 0,+ "unit": 0+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "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+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "2",+ "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,+ "width": {+ "value": 50,+ "unit": 1+ },+ "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": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/Toggle.esprefab b/sdk/src/ui/widgets/prefabs/Toggle.esprefabnew file mode 100644index 000000000..8b87acdd4--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/Toggle.esprefab@@ -0,0 +1,372 @@+{+ "version": "2",+ "name": "Toggle",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Toggle",+ "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,+ "width": {+ "value": 28,+ "unit": 0+ },+ "height": {+ "value": 28,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "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,+ "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.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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/src/ui/widgets/prefabs/generated.ts b/sdk/src/ui/widgets/prefabs/generated.tsnew file mode 100644index 000000000..cd792b452--- /dev/null+++ b/sdk/src/ui/widgets/prefabs/generated.ts@@ -0,0 +1,1901 @@+// AUTO-GENERATED by tests/ui-widget-prefabs.gen.test.ts — do not edit by hand.+import type { PrefabData } from '../../../prefab/types';++export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = {+ "Button": {+ "version": "2",+ "name": "Button",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Button",+ "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,+ "width": {+ "value": 140,+ "unit": 0+ },+ "height": {+ "value": 40,+ "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": 1,+ "g": 1,+ "b": 1,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Label",+ "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,+ "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": "Text",+ "data": {+ "content": "Button",+ "fontFamily": "Arial",+ "fontSize": 14,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "align": 1,+ "verticalAlign": 1,+ "wordWrap": false,+ "overflow": 0,+ "lineHeight": 1.2,+ "bold": false,+ "italic": false,+ "strokeColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "strokeWidth": 0,+ "shadowColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "shadowBlur": 0,+ "shadowOffsetX": 0,+ "shadowOffsetY": 0,+ "richText": false+ }+ }+ ],+ "visible": true+ }+ ]+ },+ "Toggle": {+ "version": "2",+ "name": "Toggle",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Toggle",+ "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,+ "width": {+ "value": 28,+ "unit": 0+ },+ "height": {+ "value": 28,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "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,+ "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.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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "visible": true+ }+ ]+ },+ "Slider": {+ "version": "2",+ "name": "Slider",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Slider",+ "parent": null,+ "children": [+ "2",+ "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,+ "width": {+ "value": 200,+ "unit": 0+ },+ "height": {+ "value": 18,+ "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+ }+ }+ ],+ "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,+ "width": {+ "value": 14,+ "unit": 0+ },+ "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": -7,+ "unit": 0+ },+ "marginTop": {+ "value": 0,+ "unit": 0+ },+ "marginRight": {+ "value": 0,+ "unit": 0+ },+ "marginBottom": {+ "value": 0,+ "unit": 0+ },+ "insetLeft": {+ "value": 50,+ "unit": 1+ },+ "insetTop": {+ "value": 0,+ "unit": 0+ },+ "insetRight": {+ "value": 0,+ "unit": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "texture": 0,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "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+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "2",+ "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,+ "width": {+ "value": 50,+ "unit": 1+ },+ "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": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "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,+ "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,+ "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+ }+ }+ ],+ "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,+ "width": {+ "value": 40,+ "unit": 1+ },+ "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": 2+ },+ "insetBottom": {+ "value": 0,+ "unit": 0+ }+ }+ },+ {+ "type": "UIVisual",+ "data": {+ "visualType": 1,+ "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": 1,+ "material": 0,+ "enabled": true+ }+ }+ ],+ "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,+ "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": "UIInteraction",+ "data": {+ "hovered": false,+ "pressed": false,+ "justPressed": false,+ "justReleased": false+ }+ },+ {+ "type": "StateMachine",+ "data": {+ "current": "normal",+ "previous": ""+ }+ },+ {+ "type": "StateVisuals",+ "data": {+ "targetGraphic": 0,+ "transitionFlags": 1,+ "fadeDuration": 0,+ "states": [+ {+ "name": "normal",+ "r": 0.22,+ "g": 0.22,+ "b": 0.26,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "hover",+ "r": 0.28,+ "g": 0.28,+ "b": 0.32,+ "a": 1,+ "sprite": 0,+ "scale": 1+ },+ {+ "name": "pressed",+ "r": 0.18,+ "g": 0.18,+ "b": 0.22,+ "a": 1,+ "sprite": 0,+ "scale": 1+ }+ ]+ }+ }+ ],+ "visible": true+ },+ {+ "prefabEntityId": "1",+ "name": "Label",+ "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,+ "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": "Text",+ "data": {+ "content": "One",+ "fontFamily": "Arial",+ "fontSize": 14,+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 1+ },+ "align": 1,+ "verticalAlign": 1,+ "wordWrap": false,+ "overflow": 0,+ "lineHeight": 1.2,+ "bold": false,+ "italic": false,+ "strokeColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "strokeWidth": 0,+ "shadowColor": {+ "r": 0,+ "g": 0,+ "b": 0,+ "a": 1+ },+ "shadowBlur": 0,+ "shadowOffsetX": 0,+ "shadowOffsetY": 0,+ "richText": false+ }+ }+ ],+ "visible": true+ }+ ]+ }+};++export const BUILTIN_UI_WIDGET_NAMES = ["Button","Toggle","Slider","Progress","Dropdown"] as const;diff --git a/sdk/src/ui/widgets/toPrefab.ts b/sdk/src/ui/widgets/toPrefab.tsnew file mode 100644index 000000000..638f5d03d--- /dev/null+++ b/sdk/src/ui/widgets/toPrefab.ts@@ -0,0 +1,113 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file ui/widgets/toPrefab.ts+ * @brief widgetToPrefab — turn an imperative widget builder into PrefabData.+ *+ * The widget factories (createButton, createSlider, …) are the single source of+ * a control's structure + default styling. Running one against a lightweight+ * recording World captures its spawn/insert/setParent calls as plain data, which+ * `extractPrefab` serialises into a shippable `.esprefab`. So the editor gets a+ * drop-in, themed control asset generated from the exact same code the runtime+ * uses — no hand-authored duplicate to drift.+ */+import type { World } from '../../world';+import type { Entity } from '../../types';+import { extractPrefab, type ExtractEntity } from '../../prefab/sceneInstance';+import type { PrefabData, ComponentData } from '../../prefab/types';++interface RecEntity {+ id: number;+ parent: number | null;+ children: number[];+ components: ComponentData[];+}++/** Minimal World stand-in: records the tree a builder constructs, no C++/wasm. */+class RecordingWorld {+ private next = 0;+ readonly entities = new Map<number, RecEntity>();++ spawn(): number {+ const id = this.next++;+ this.entities.set(id, { id, parent: null, children: [], components: [] });+ return id;+ }++ insert(entity: number, comp: { _name: string }, data: unknown): void {+ const ent = this.entities.get(entity);+ if (!ent) return;+ const clone = JSON.parse(JSON.stringify(data)) as unknown;+ const existing = ent.components.find((c) => c.type === comp._name);+ if (existing) existing.data = clone as ComponentData['data'];+ else ent.components.push({ type: comp._name, data: clone as ComponentData['data'] });+ }++ setParent(child: number, parent: number): void {+ const c = this.entities.get(child);+ if (!c) return;+ if (c.parent !== null) {+ const old = this.entities.get(c.parent);+ if (old) old.children = old.children.filter((x) => x !== child);+ }+ c.parent = parent;+ const p = this.entities.get(parent);+ if (p && !p.children.includes(child)) p.children.push(child);+ }++ get(entity: number, comp: { _name: string }): unknown {+ return this.entities.get(entity)?.components.find((c) => c.type === comp._name)?.data;+ }++ has(entity: number, comp: { _name: string }): boolean {+ return this.entities.get(entity)?.components.some((c) => c.type === comp._name) ?? false;+ }++ valid(entity: number): boolean {+ return this.entities.has(entity);+ }++ remove(entity: number, comp: { _name: string }): void {+ const ent = this.entities.get(entity);+ if (ent) ent.components = ent.components.filter((c) => c.type !== comp._name);+ }+}++/** Name a captured entity for the outliner: root → widget name; a text node → Label. */+function entityName(ent: RecEntity, rootId: number, widgetName: string): string {+ if (ent.id === rootId) return widgetName;+ return ent.components.some((c) => c.type === 'Text') ? 'Label' : 'Node';+}++/**+ * Run `build` against a recording World and serialise the resulting subtree to a+ * PrefabData named `name`. `build` returns the root entity (as the factories do).+ */+export function widgetToPrefab(build: (world: World) => Entity, name: string): PrefabData {+ const world = new RecordingWorld();+ const root = build(world as unknown as World) as unknown as number;++ // Only the root's subtree — a node parented outside it (e.g. a popup on the+ // canvas) would otherwise become a stray second root in the prefab.+ const subtree = new Set<number>();+ const stack = [root];+ while (stack.length) {+ const id = stack.pop()!;+ if (subtree.has(id)) continue;+ subtree.add(id);+ stack.push(...(world.entities.get(id)?.children ?? []));+ }++ const entities: ExtractEntity[] = [...subtree].map((id) => {+ const e = world.entities.get(id)!;+ return {+ id: e.id,+ name: entityName(e, root, name),+ parent: e.parent,+ children: e.children.filter((c) => subtree.has(c)),+ components: e.components,+ visible: true,+ };+ });+ return extractPrefab(entities, root, name);+}diff --git a/sdk/tests/ui-widget-prefabs.gen.test.ts b/sdk/tests/ui-widget-prefabs.gen.test.tsnew file mode 100644index 000000000..54145f67a--- /dev/null+++ b/sdk/tests/ui-widget-prefabs.gen.test.ts@@ -0,0 +1,123 @@+// Generates the built-in UI widget prefabs from the factories (single source)+// and verifies the captured tree. Writing the .esprefab files is the codegen;+// the assertions are the guard that the factory still round-trips to a prefab.+import { describe, it, expect, afterAll } from 'vitest';+import { writeFileSync, mkdirSync } from 'node:fs';+import { resolve } from 'node:path';+import type { World } from '../src/world';+import type { PrefabData } from '../src/prefab/types';+import { widgetToPrefab } from '../src/ui/widgets/toPrefab';+import { createButton } from '../src/ui/widgets/button';+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 { themeColors } from '../src/ui/theme/tokens';+import { px } from '../src/ui/core/dimension';++const OUT_DIR = resolve(__dirname, '../src/ui/widgets/prefabs');+// eslint-disable-next-line @typescript-eslint/no-explicit-any+const noEvents = { on: () => {} } as any;+const c = themeColors();++function entityById(p: PrefabData, id: string) {+ return p.entities.find((e) => e.prefabEntityId === id)!;+}+function typesOf(p: PrefabData, id: string): string[] {+ return entityById(p, id).components.map((cc) => cc.type);+}++const GENERATED: Record<string, PrefabData> = {};++function generate(name: string, build: (w: World) => number): PrefabData {+ const prefab = widgetToPrefab(build, name);+ mkdirSync(OUT_DIR, { recursive: true });+ writeFileSync(resolve(OUT_DIR, `${name}.esprefab`), JSON.stringify(prefab, null, 2) + '\n');+ GENERATED[name] = prefab;+ return prefab;+}++// Emit the SDK-exported data module the editor's "Create → UI" menu instantiates.+afterAll(() => {+ const names = Object.keys(GENERATED);+ const body =+ '// AUTO-GENERATED by tests/ui-widget-prefabs.gen.test.ts — do not edit by hand.\n' ++ "import type { PrefabData } from '../../../prefab/types';\n\n" ++ `export const BUILTIN_UI_PREFABS: Record<string, PrefabData> = ${JSON.stringify(GENERATED, null, 2)};\n\n` ++ `export const BUILTIN_UI_WIDGET_NAMES = ${JSON.stringify(names)} as const;\n`;+ writeFileSync(resolve(OUT_DIR, 'generated.ts'), body);+});++describe('UI widget prefab codegen', () => {+ it('Button: factory → prefab captures the full clickable tree + label', () => {+ const prefab = generate('Button', (world) =>+ createButton({+ world, events: noEvents,+ node: { width: px(140), height: px(40) },+ states: {+ normal: { color: c.control },+ hover: { color: c.controlHover },+ pressed: { color: c.controlActive },+ },+ text: { content: 'Button', color: c.onPrimary, fontSize: 14 },+ }) as unknown as number,+ );++ const root = typesOf(prefab, prefab.rootEntityId);+ expect(root).toEqual(expect.arrayContaining([+ 'Transform', 'UINode', 'UIVisual', 'Interactable', 'UIInteraction', 'StateMachine', 'StateVisuals',+ ]));+ const rootEnt = entityById(prefab, prefab.rootEntityId);+ expect(rootEnt.children.length).toBe(1);+ const label = entityById(prefab, rootEnt.children[0]!);+ expect(label.components.map((x) => x.type)).toEqual(expect.arrayContaining(['UINode', 'Text']));+ expect(label.parent).toBe(prefab.rootEntityId);+ });++ it('Toggle: box + checkmark child', () => {+ const prefab = generate('Toggle', (world) =>+ createToggle({+ world, events: noEvents,+ node: { width: px(28), height: px(28) },+ background: { color: c.control },+ interactionStates: {+ normal: { color: c.control }, hover: { color: c.controlHover }, pressed: { color: c.controlActive },+ },+ check: { color: c.primary }, isOn: true,+ }).entity as unknown as number,+ );+ expect(typesOf(prefab, prefab.rootEntityId)).toEqual(expect.arrayContaining(['UINode', 'Interactable', 'StateVisuals']));+ expect(entityById(prefab, prefab.rootEntityId).children.length).toBeGreaterThanOrEqual(1);+ });++ it('Slider: track + fill + handle', () => {+ const prefab = generate('Slider', (world) =>+ createSlider({+ world, 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);+ });++ it('Progress: track + fill', () => {+ const prefab = generate('Progress', (world) =>+ createProgress({+ world, node: { width: px(200), height: px(14) },+ fill: { color: c.primary }, value: 0.4,+ }).entity as unknown as number,+ );+ expect(entityById(prefab, prefab.rootEntityId).children.length).toBe(1);+ });++ it('Dropdown: button + label (popup lives outside the subtree)', () => {+ const prefab = generate('Dropdown', (world) =>+ createDropdown<string>({+ world, events: noEvents,+ node: { width: px(150), height: px(34) },+ options: ['One', 'Two', 'Three'], optionToLabel: (o) => o, optionHeight: 30,+ }).entity as unknown as number,+ );+ expect(typesOf(prefab, prefab.rootEntityId)).toEqual(expect.arrayContaining(['UINode', 'Interactable']));+ });+});