Skip to content

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.

test(ui): verify live focus and dynamic runtime controls (#77)

YHHad2a3d0a6bf2
diff --git a/desktop b/desktop
index 243331363..82cfeb7c1 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 2433313635d09e5bb5e11d1dbadb535facbef810
+Subproject commit 82cfeb7c12882d3a635ccef5338a97545d80e339
diff --git a/examples/ui-localization-debug/README.md b/examples/ui-localization-debug/README.md
index f4aa595b4..17c591c20 100644
--- a/examples/ui-localization-debug/README.md
+++ b/examples/ui-localization-debug/README.md
@@ -72,3 +72,17 @@ Stop recording and click again: game reactions continue, history stays fixed.
Toggle the panel off and read the diagnostic snapshot to verify recording is
false. Stop/Start Play rebuilds the world; recording defaults off with no old
history. This covers browser Play, not desktop custom-scheme or device QA.
+
+
+Focus now samples the current world's actual Tab policy every 250 ms. During
+Play it reads FocusManager focus and visibility state through the realm; in
+Edit it shows authored traversal policy. Selecting a row only inspects the
+entity. Game focus differs from DOM/browser focus; the panel does not assert
+keyboard delivery success. Connected-device focus queries remain unavailable.
+
+In the browser Play fixture, Inside also toggles a runtime-generated button.
+Focus lists it with Tab index 2, Elements shows its actual hierarchy and
+components, and a second activation deletes it. Start Play, open Focus, click
+Inside, press Tab and then Enter to exercise real keyboard activation and
+auto-updating traversal. Continuous Tab may move browser focus out of the
+game iframe; this remains an input follow-up, not a passed keyboard gate.
diff --git a/examples/ui-localization-debug/VALIDATION.md b/examples/ui-localization-debug/VALIDATION.md
index 6f2a6f5ed..e9b75a588 100644
--- a/examples/ui-localization-debug/VALIDATION.md
+++ b/examples/ui-localization-debug/VALIDATION.md
@@ -177,3 +177,30 @@ snapshot; live-game-only dialogs and scripts need runtime acceptance separately.
- No Electron/native runner launched. This fixture does not establish desktop
custom-scheme, device, IME/accessibility, shaping or performance acceptance.
RM-009 remains In Progress.
+
+
+## Live focus and dynamic UI — 2026-10-09
+
+- Engine #76 / editor #13 merged after editor Typecheck + tests passed at the
+ fixed current head. Android workflow did not trigger for the verification
+ tool/docs/gitlink-only engine change; no new Android evidence is claimed.
+- Focus view now reads actual runtime FocusManager and inspectFocusTraversal
+ facts, polling only while mounted with one request in flight. Edit-world
+ traversal is live too. Failed/late replies clear or cannot replace data from
+ a different session; missing manager is shown as unavailable, not no focus.
+- Real browser Play click spawns Runtime button (Focusable tabIndex=2): Focus
+ grows from 2 to 3 entries; Elements shows Canvas/OuterMask/InnerMask/Runtime
+ button and actual 150x32 UINode/component values. Selecting it uses a
+ spawned-world reference. Deleting the selected node removes its row and
+ old component details.
+- Native browser Tab input changes FocusManager to Inside with focusVisible;
+ Enter activates its project handler and deletes the dynamic node. Focus
+ list automatically returns to 2 entries. These are actual key events.
+- Found follow-up: repeated Tab can move DOM/browser focus out of the iframe.
+ Game-manager focus and browser focus are different states. Complete keyboard
+ traversal, desktop custom-scheme, devices, IME/accessibility, shaping and
+ performance remain open; no success verdict is inferred from a focus record.
+- 14 targeted panel/helper/event/i18n tests pass, including dynamic updates,
+ read-only policy/manager capture, request coalescing and late-response
+ rejection. Typecheck, production build and CSS-variable gate pass.
+- No local Electron/native test runner launched. RM-009 remains In Progress.
diff --git a/tools/ui-events-play-browser.tsx b/tools/ui-events-play-browser.tsx
index fd2d81959..48bfbe2f4 100644
--- a/tools/ui-events-play-browser.tsx
+++ b/tools/ui-events-play-browser.tsx
@@ -6,7 +6,10 @@ import '../desktop/src/theme/tokens.css';
import '../desktop/src/theme/global.css';
import '../desktop/src/theme/controls.css';
import '../desktop/src/theme/uiTextDebug.css';
+import { PlayInspect } from '../desktop/src/engine/PlayInspect';
import { PlayRealm } from '../desktop/src/engine/PlayRealm';
+import { UIDebuggerFocus } from '../desktop/src/panels/UIDebuggerFocus';
+import { UIDebuggerElements } from '../desktop/src/panels/UIDebuggerElements';
import { UIDebuggerEvents } from '../desktop/src/panels/UIDebuggerEvents';
import { useSelection } from '../desktop/src/store/selectionStore';
// Only staging uses an adapter; the realm protocol and actual game are unchanged.
@@ -17,6 +20,7 @@ import { useSelection } from '../desktop/src/store/selectionStore';
const scene = await (await fetch('/__events-scene.json')).json();
// Decorative ancestors deliberately accept bubbling, without becoming pointer targets.
for (const entity of scene.entities) {
+ if (['Inside', 'Partial'].includes(entity.name)) entity.components.push({ type: 'Focusable', data: { tabIndex: entity.name === 'Inside' ? 0 : 1 } });
if (['InnerMask', 'OuterMask', 'Canvas'].includes(entity.name))
entity.components.push({ type: 'Interactable', data: { enabled: true, raycastTarget: false, blockRaycast: false } });
}
@@ -26,7 +30,8 @@ function Fixture() {
const attach = useCallback((element: HTMLDivElement | null) => { if(element) PlayRealm.attach(element); }, []);
const [state, setState] = useState('Ready to start');
const [mounted, setMounted] = useState(true);
- const start = async () => { setState('Starting'); try { await PlayRealm.start({ sceneData: scene, assetManifest: {}, physicsEnabled: false }); setState('Play ready'); } catch(error) { setState(String(error)); } };
+ const [view, setView] = useState('events');
+ const start = async () => { setState('Starting'); try { await PlayRealm.start({ sceneData: scene, assetManifest: {}, physicsEnabled: false }); PlayInspect.start(); setState('Play ready'); } catch(error) { setState(String(error)); } };
const inspect = async () => {
const ref = useSelection.getState().selectedRef;
const data = await PlayRealm.snapshot(ref && 'live' in ref ? ref.live : null);
@@ -35,11 +40,11 @@ function Fixture() {
};
return <main style={{ padding: 16, height: '100vh', display: 'flex', flexDirection: 'column', gap: 12 }}>
<h2>UI Events · production Play realm browser verification</h2>
- <div><button onClick={() => void start()}>Start Play</button> <button onClick={() => PlayRealm.stop()}>Stop Play</button> <button onClick={() => setMounted(value => !value)}>Toggle panel</button> <button onClick={() => void inspect()}>Read runtime snapshot</button></div>
+ <div><button onClick={() => void start()}>Start Play</button> <button onClick={() => { PlayInspect.stop(); PlayRealm.stop(); }}>Stop Play</button> <button onClick={() => setMounted(value => !value)}>Toggle panel</button> <button onClick={() => void inspect()}>Read runtime snapshot</button> <button onClick={() => setView('events')}>Events</button> <button onClick={() => setView('focus')}>Focus</button> <button onClick={() => setView('elements')}>Elements</button></div>
<p role="status">{realm.playing ? 'Playing' : 'Stopped'} · {realm.ready ? 'Ready' : 'Not ready'} · {realm.error ?? ''}</p>
<div style={{ display: 'flex', gap: 16, flex: 1, minHeight: 0 }}>
<div style={{ width: 800, height: 600, flexShrink: 0 }} ref={attach} />
- <section style={{ flex: 1, minWidth: 300, display: 'flex', flexDirection: 'column', overflow: 'auto' }}>{mounted && <UIDebuggerEvents />}</section>
+ <section style={{ flex: 1, minWidth: 300, display: 'flex', flexDirection: 'column', overflow: 'auto' }}>{mounted && (view === 'events' ? <UIDebuggerEvents /> : view === 'focus' ? <UIDebuggerFocus /> : <UIDebuggerElements />)}</section>
</div>
<output style={{maxHeight: 90, overflow: 'auto', fontSize: 11}}>{state}</output>
<output aria-label="Selected runtime nodes">{JSON.stringify(selected)}</output>
diff --git a/tools/ui-events-play-project.ts b/tools/ui-events-play-project.ts
index 2dfadcce9..54bd1deb0 100644
--- a/tools/ui-events-play-project.ts
+++ b/tools/ui-events-play-project.ts
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Disposable browser game script: reactions are driven by real UI clicks.
-import { addSystemToSchedule, defineSystem, Schedule, Res, GetWorld, UIEvents, Text, UINode, px, type UIEventQueue, type World } from 'esengine';
+import { addSystemToSchedule, defineSystem, Schedule, Res, GetWorld, UIEvents, Text, UINode, Transform, UIVisual, Interactable, Focusable, px, type Entity, type UIEventQueue, type World } from 'esengine';
const installed = new WeakSet<World>();
addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld()], (events: UIEventQueue, world: World) => {
if (installed.has(world)) return;
@@ -9,11 +9,22 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld()], (
installed.add(world);
const partial = world.findEntityByName('Partial')!;
const inner = world.findEntityByName('InnerMask')!;
- let count = 0;
+ let count = 0, dynamic: Entity | null = null;
events.on(inside, 'click', () => {
count++;
world.insert(inside, Text, { ...world.get(inside, Text), content: `Clicks ${count}` });
world.insert(inside, UINode, { ...world.get(inside, UINode), width: px(count % 2 ? 160 : 120) });
+ if (dynamic !== null) { world.despawn(dynamic); dynamic = null; }
+ else {
+ dynamic = world.spawn('Runtime button');
+ world.insert(dynamic, Transform, {});
+ world.insert(dynamic, UINode, { position: 1, width: px(150), height: px(32), insetLeft: px(20), insetTop: px(125) });
+ world.insert(dynamic, UIVisual, { visualType: 1, color: { r: 0.2, g: 0.55, b: 0.3, a: 1 } });
+ world.insert(dynamic, Text, { content: 'Runtime button', fontFamily: 'Arial', fontSize: 16 });
+ world.insert(dynamic, Interactable, { enabled: true, raycastTarget: true, blockRaycast: true });
+ world.insert(dynamic, Focusable, { tabIndex: 2 });
+ world.setParent(dynamic, inner);
+ }
});
events.on(inner, 'click', event => {
if (event.target === partial) { event.stopPropagation(); event.preventDefault(); }