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.

fix(sdk): lay editor UI out in the design box, not the panel aspect

esengine9e5e57679f6b
diff --git a/sdk/src/camera/uiLayoutRect.ts b/sdk/src/camera/uiLayoutRect.ts
index 2cd75415e..93dd2febe 100644
--- a/sdk/src/camera/uiLayoutRect.ts
+++ b/sdk/src/camera/uiLayoutRect.ts
@@ -94,16 +94,15 @@ export function uiLayoutRect(
let halfW = cam.halfW;
let halfH = cam.halfH;
- if (cam.entity === EDITOR_VIEW_ENTITY && canvas && height > 0) {
- const aspect = width / height;
- halfH = computeEffectiveOrthoSize(
- canvas.designResolution.y / 2,
- canvas.designResolution.x / canvas.designResolution.y,
- aspect,
- canvas.scaleMode,
- canvas.matchWidthOrHeight,
- );
- halfW = halfH * aspect;
+ if (cam.entity === EDITOR_VIEW_ENTITY && canvas && width > 0 && height > 0) {
+ // Lay UI out in the authored design box (1 unit = 1 design px), independent of the
+ // editor panel's aspect — the editor is then WYSIWYG with the design-frame overlay:
+ // edge-anchored UI sits at the design-resolution corners, exactly as it ships at
+ // that resolution. The free editor camera renders this fixed box through its zoomed
+ // viewProjection, so UI scales with zoom without reflowing. Previewing adaptation to
+ // a *different* screen aspect is the device simulator's concern, not the base box.
+ halfW = canvas.designResolution.x / 2;
+ halfH = canvas.designResolution.y / 2;
}
return {
diff --git a/sdk/tests/ui-layout-rect.test.ts b/sdk/tests/ui-layout-rect.test.ts
index 91fc1fefb..9eb5969d3 100644
--- a/sdk/tests/ui-layout-rect.test.ts
+++ b/sdk/tests/ui-layout-rect.test.ts
@@ -38,11 +38,12 @@ describe('uiLayoutRect', () => {
});
});
- it('the editor box adapts to the viewport aspect via the scale mode', () => {
- // A square viewport: Expand keeps the design width, so height grows to 1280.
+ it('the editor box is the design box regardless of viewport aspect (WYSIWYG with the frame)', () => {
+ // A square viewport must NOT reshape the UI box — it stays the authored 1280×720, so
+ // edge-anchored UI sits at the design-resolution corners, matching the design frame.
const cam = { entity: EDITOR_VIEW_ENTITY, cameraX: 0, cameraY: 0, halfW: 160, halfH: 90 };
expect(uiLayoutRect(cam, canvas, 1000, 1000)).toEqual({
- left: -640, right: 640, bottom: -640, top: 640,
+ left: -640, right: 640, bottom: -360, top: 360,
});
});