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
fix(ui): exclude hierarchically hidden dialogs from focus scope (#80)
YHH60ab2acf57c0
diff --git a/examples/ui-localization-debug/README.md b/examples/ui-localization-debug/README.mdindex 6ca3974da..3330a62d6 100644--- a/examples/ui-localization-debug/README.md+++ b/examples/ui-localization-debug/README.md@@ -101,3 +101,8 @@ marks the runtime button as a UIDialog; the Focus view should mark Inside andPartial outside the dialog and clear their old game focus. Tab then Enterconfirms the dialog. D disables the current focus; E restores those controls;R removes the test dialog. These keys run normal project systems in Play.+++While the test dialog is open, H hides its parent container and V restores it.+The Focus view should free the visible page controls while the dialog is+hierarchically hidden, then restrict traversal again when its parent returns.diff --git a/examples/ui-localization-debug/VALIDATION.md b/examples/ui-localization-debug/VALIDATION.mdindex b2b6e607b..6dd705b42 100644--- a/examples/ui-localization-debug/VALIDATION.md+++ b/examples/ui-localization-debug/VALIDATION.md@@ -258,3 +258,21 @@ snapshot; live-game-only dialogs and scripts need runtime acceptance separately.- No Electron/native runner launched. Multiple/nested modal arbitration,real devices, IME/assistive technology, desktop custom-scheme, complex textshaping and layout-cache performance remain open. RM-009 is In Progress.+++## Hidden dialog ancestor — 2026-10-09++- Active-dialog filtering now uses the same resolved hierarchical visibility+ as control traversal. A dialog whose own display is Flex but whose ancestor+ is hidden cannot exclude the visible page controls from the Tab ring.+ If host visibility is unavailable, the inspection still reports that limit.+- Built-in browser, production Play host and actual game keys: click Inside,+ M opens the real UIDialog, Tab focuses Runtime button. H hides its parent:+ 2 page controls become navigable, the dialog entry is hierarchically hidden,+ and old focus clears. Tab focuses Inside. V shows the parent again: page+ entries become outside-dialog, focus clears, and Tab returns to the dialog.+- 39 targeted SDK tests, SDK build and 16 API/built declaration checks pass.+ Tests cover ancestor-hidden modal restoration/despawn and one visible modal+ remaining active alongside another hidden modal. No local Electron/native+ runner launched. Modal stacking order, real devices, IME/accessibility,+ desktop custom-scheme, text shaping and cache performance remain open.diff --git a/sdk/src/ui/input/focus-inspection.ts b/sdk/src/ui/input/focus-inspection.tsindex 76f1c2078..6bc1c9dba 100644--- a/sdk/src/ui/input/focus-inspection.ts+++ b/sdk/src/ui/input/focus-inspection.ts@@ -32,7 +32,8 @@ export function inspectFocusTraversal(world: FocusInspectionWorld): FocusTraversconst registry = world.getCppRegistry();const visibilityResolved = !!(registry && engine?.getUINodeHiddenInTree);const roots = new Set(world.getEntitiesWithComponents([UIDialog])- .filter(entity => isDialogOpen(world, entity)));+ .filter(entity => isDialogOpen(world, entity)+ && (!visibilityResolved || !engine!.getUINodeHiddenInTree!(registry!, entity))));const entries: FocusTraversalEntry[] = [];for (const entity of world.getEntitiesWithComponents([Focusable])) {if (!world.valid(entity)) continue;diff --git a/sdk/tests/ui-focus-inspection.test.ts b/sdk/tests/ui-focus-inspection.test.tsindex c2dd24cce..cf62a2f8d 100644--- a/sdk/tests/ui-focus-inspection.test.ts+++ b/sdk/tests/ui-focus-inspection.test.ts@@ -67,3 +67,33 @@ describe('focus inspection shares runtime traversal', () => {expect(inspectFocusTraversal(harness.app.world).visibilityResolved).toBe(false);});});+++it('does not trap visible controls behind a dialog hidden by an ancestor', () => {+ const world = harness.app.world;+ const outside = control(0), dialog = control(1);+ const host = world.spawn();+ world.insert(host, UINode, { display: UIDisplay.None });+ world.insert(dialog, Parent, { entity: host });+ world.insert(dialog, UIDialog);+ world.insert(dialog, UINode, { display: UIDisplay.Flex });+ let hidden = true;+ harness.module.getUINodeHiddenInTree = (_registry: unknown, entity: Entity) => hidden && entity === dialog;+ expect(inspectFocusTraversal(world).entries.map(e => e.skipped)).toEqual([null, 'hidden']);+ hidden = false;+ expect(inspectFocusTraversal(world).entries.map(e => e.skipped)).toEqual(['outside-dialog', null]);+ world.despawn(dialog);+ expect(inspectFocusTraversal(world).entries.find(e => e.entity === outside)?.skipped).toBeNull();+});++it('keeps a visible modal active when a second modal is hierarchically hidden', () => {+ const world = harness.app.world;+ const background = control(0), visible = control(1), hidden = control(2);+ for (const entity of [visible, hidden]) {+ world.insert(entity, UIDialog);+ world.insert(entity, UINode, { display: UIDisplay.Flex });+ }+ harness.module.getUINodeHiddenInTree = (_registry: unknown, entity: Entity) => entity === hidden;+ expect(inspectFocusTraversal(world).entries.map(e => [e.entity, e.skipped]))+ .toEqual([[background, 'outside-dialog'], [visible, null], [hidden, 'hidden']]);+});diff --git a/tools/ui-events-play-browser.tsx b/tools/ui-events-play-browser.tsxindex 6c0d77def..48a158494 100644--- a/tools/ui-events-play-browser.tsx+++ b/tools/ui-events-play-browser.tsx@@ -41,7 +41,7 @@ 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={() => { 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>- <small>Game keys: M opens the runtime button as a dialog; R closes it; D disables current focus; E restores disabled controls.</small>+ <small>Game keys: M opens the runtime button as a dialog; R closes it; D disables current focus; E restores disabled controls; H hides the dialog parent; V shows it again.</small><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} />diff --git a/tools/ui-events-play-project.ts b/tools/ui-events-play-project.tsindex da9f9b2da..5284e3fc8 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, Transform, UIVisual, Interactable, Focusable, px, Input, FocusManager, UIDialog, type InputState, type FocusManagerState, type Entity, type UIEventQueue, type World } from 'esengine';+import { addSystemToSchedule, defineSystem, Schedule, Res, GetWorld, UIEvents, Text, UINode, Transform, UIVisual, Interactable, Focusable, px, Input, FocusManager, UIDialog, UIDisplay, type InputState, type FocusManagerState, type Entity, type UIEventQueue, type World } from 'esengine';const installed = new WeakMap<World, () => void>();addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld(), Res(Input), Res(FocusManager)], (events: UIEventQueue, world: World, input: InputState, focus: FocusManagerState) => {const update = installed.get(world);@@ -9,7 +9,7 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld(), Reif (inside === null) return;const partial = world.findEntityByName('Partial')!;const inner = world.findEntityByName('InnerMask')!;- let count = 0, dynamic: Entity | null = null;+ let count = 0, dynamic: Entity | null = null, dialogHost: Entity | null = null;const restore = new Set<Entity>();installed.set(world, () => {if (input.isKeyPressed('KeyM') && dynamic !== null && world.valid(dynamic)) {@@ -20,6 +20,10 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld(), Reworld.remove(dynamic, UIDialog);world.insert(dynamic, Text, { ...world.get(dynamic, Text), content: 'Runtime button' });}+ if (dialogHost !== null && world.valid(dialogHost)) {+ if (input.isKeyPressed('KeyH')) world.insert(dialogHost, UINode, { ...world.get(dialogHost, UINode), display: UIDisplay.None });+ if (input.isKeyPressed('KeyV')) world.insert(dialogHost, UINode, { ...world.get(dialogHost, UINode), display: UIDisplay.Flex });+ }if (input.isKeyPressed('KeyD') && focus.focusedEntity !== null) {const entity = focus.focusedEntity;world.insert(entity, Interactable, { ...world.get(entity, Interactable), enabled: false });@@ -35,8 +39,12 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld(), Recount++;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; }+ if (dynamic !== null) { world.despawn(dynamic); dynamic = null; if (dialogHost !== null) world.despawn(dialogHost); dialogHost = null; }else {+ dialogHost = world.spawn('Runtime dialog host');+ world.insert(dialogHost, Transform, {});+ world.insert(dialogHost, UINode, { position: 1, width: px(200), height: px(200), insetLeft: px(0), insetTop: px(0) });+ world.setParent(dialogHost, inner);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) });@@ -44,7 +52,7 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(UIEvents), GetWorld(), Reworld.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);+ world.setParent(dynamic, dialogHost);const button = dynamic;events.on(button, 'click', () => {if (!world.valid(button) || !world.has(button, UIDialog)) return;