diff --git a/docs/status/WEB-WORKSPACE-LAYOUT-20261123.md b/docs/status/WEB-WORKSPACE-LAYOUT-20261123.md new file mode 100644 index 000000000..48d3a1ecc --- /dev/null +++ b/docs/status/WEB-WORKSPACE-LAYOUT-20261123.md @@ -0,0 +1,61 @@ +# WEB-WORKSPACE-LAYOUT-20261124 status + +- case: `WEB-WORKSPACE-LAYOUT-20261124`(网页 Blender 面板可拖拽、布局可调整、区域可弹出为浮动窗口、面板内部控件不再互相遮挡) +- 类型:用户案例补缺。用户原话:“完善‘web blender’的页面,实现网页上面的控制面板可以拖拽,面板固定会影响三维设计场景查看。优化面板布局,面板内部控件不要互相遮挡,布局合理,方便使用。” +- 范围(经用户确认): + - **分区可拖**:视口↔右栏、视口↔时间线、大纲↔属性三条分隔条; + - **视口浮层可拖**:N 面板、工具架、着色/导航按钮簇; + - **区域可弹出为浮动窗口**:任意区域菜单「浮动为独立窗口 / 停靠回布局」; + - 位置记忆**全局共用一份**(所有工作区共享),带一键复位。 +- 计划:`/home/mes123456/.claude/plans/dynamic-foraging-sundae.md`(已批准);上一批浮层拖动见 `docs/status/WEB-PANEL-DRAG-20261123.md`。 + +## 改动文件 + +| 文件 | 改动 | +| --- | --- | +| `web/app/src/app/workspace-layout.tsx`(新增) | 布局状态与持久化(localStorage `web-blender.workspace-layout.v1`,纯 UI 偏好,工程数据仍只走 OPFS)、`splitStyle()` CSS 变量、`` 三条分隔条(指针拖拽 + 方向键 ±16 / Shift ±48 + Home/双击复位 + `ResizeObserver` 重测)。钳制:右栏 240–50vw、时间线 48–40vh、大纲占比 0.2–0.8。 | +| `web/app/src/app/WasmWorkspace.tsx` | 网页模式 `.workspace-grid` 写入 `splitStyle(splits)` 并渲染 ``。原生/custom 布局不受影响。 | +| `web/app/src/main.tsx` | `` 外层挂 `WorkspaceLayoutProvider`。 | +| `web/app/src/app/App.tsx` | ① 区域浮动窗口:同一 `section.area-frame` 改为 `position:fixed`(不 portal、不重挂载,WebGL 上下文与文本草稿保留),标题栏拖动、右下角缩放手柄、停靠按钮、网格占位块「已弹出为浮动窗口 · 停靠回布局」;② 区域菜单新增「浮动为独立窗口 / 停靠回布局」;③ 视口浮层接入 `useDraggablePanel`:N 面板(新增关闭 ×)、工具架、着色+导航合并为一个可拖簇;④ 「视图」菜单新增「侧栏 (N)」「工具架 (T)」,为已关闭的浮层提供恢复入口;⑤ 「窗口 → 恢复默认面板位置」同时复位分区尺寸与浮窗;⑥ 区域编辑器切换器改为:有标题栏的区域放进标题栏,无标题栏的区域(视口/时间线/节点/控制台等)才悬浮,且每个区域只保留一个 ⋮ 菜单。 | +| `web/app/src/app/use-draggable-panel.ts` | 新增可选 `bounds` 钳制:视口浮层必须整体留在 `.viewport-placeholder` 内(该容器 `overflow:hidden`,旧的全窗口钳制会把面板推到看不见的位置);泛型化 `panelRef`。 | +| `web/app/src/app/app-shell.css` | 网格轨道改为 `--ws-*` 变量且默认值与旧值逐像素一致;分隔条样式(默认透明,悬停/拖动/聚焦显示 2px 蓝线);浮窗与占位块样式;视口浮层把手样式;**快捷操作栏停靠时占用独立网格行**(不再压住各区域顶部);区域切换器默认只在悬停/聚焦时出现;属性栏窄化换行与 `min-width:0`;N 面板 `max-height` + 滚动;901–1280px 的右栏宽度改用变量(原为写死 290px,会覆盖拖动结果)。 | +| `web/app/src/app/desktop-menus.css` | 状态栏隐藏时的网格行同步快捷操作栏行高。 | +| `web/tests/e2e/wbv2-workspace-layout-production.spec.ts`(新增) | 三条用例:分隔条拖动/持久化/键盘微调/双击复位;区域浮出/拖动/停靠;视口浮层拖动、N 面板关闭与恢复、浮层始终留在视口内。 | +| `tests/golden/WEB-WORKSPACE-LAYOUT-20261123/` | 证据:`splits.json`、`floating-area.json`、`floating-properties.png`、`viewport-overlays.json`,均 `acceptance: "NOT_CLAIMED"`。 | + +## 过程中发现并处理的既有或自引入缺口 + +1. **901–1280px 窗口下右栏宽度写死 `290px`**(`app-shell.css` 媒体查询):会覆盖拖拽变量,使分隔条在这个区间完全无效。改为 `var(--ws-right-width, 290px)`,并让首次加载在 ≤1280px 时仍以 290px 起步,窄窗口观感不变。 +2. **区域切换器压住标题栏自己的 ⋮ 菜单**(自引入):首个版本把切换器叠在标题栏右上角,Playwright 报 “subtree intercepts pointer events”,用户也点不到菜单。改为切换器进标题栏;旧用例要求切换器内仍有 ⋮,故保留切换器内的 ⋮、标题栏不再重复渲染一个。 +3. **视口标题栏并非所有工作区都隐藏**(自引入后发现):`[data-workspace="Scripting"] .viewport-area > .editor-header { display:flex }`。第一版按类名一刀切删掉视口标题栏,`web-manual-ui-gaps.spec.ts` 在 HEAD 上通过、在我的改动上失败;A/B(`git stash` 后仅跑该用例)确认属回归。改为由 `AreaEditorContext.workspace` 决定。 +4. **快捷操作栏停靠时覆盖各区域顶部约 35px**(既有):改为 `.blender-app` 网格里的独立行,折叠时 24px、浮出时为 0;`.render-result-view` 不再需要 `padding-top:35px` 补偿。 +5. **N 面板被本身内容撑到 714px 宽**(既有,线上实测发现):`.viewport-sidebar` 没有宽度约束,着色分组的 `select` 把它撑到 509px,整个面板占去视口 70% 以上,正是用户说的“面板影响查看三维场景”。给面板加 `max-width: min(70%, 420px)`、着色分组固定 200px 并允许内部换行;实测宽度 714 → 407px,并加进本次用例断言(`≤424px`)。 + +## 流程与结果(Chromium,OPFS,开发服务器) + +1. `cd web && npm run typecheck`:通过(exit 0,多轮)。 +2. `npx playwright test tests/e2e/wbv2-workspace-layout-production.spec.ts --workers=1`: + - `partition splitters resize, persist and reset the workspace areas` — 拖右栏分隔条 → `splits.rightWidth` 由 320 变为 456 → `.properties-area` 加宽、视口变窄 → 拖时间线上移 → 时间线变高 → `reload` 后尺寸保持 → 方向键 → 双击复位回 320。 + - `an area pops out as a floating window and docks back` — 属性区菜单「浮动为独立窗口」→ `position:fixed`、`data-floating="true"`、占位块出现、入 localStorage → 拖标题栏 (140,80) → 停靠回网格、`floating` 清空。 + - `viewport overlays move out of the model and stay inside the viewport` — N 面板拖动后仍在视口矩形内 → × 关闭 → 「视图 → 侧栏」恢复 → 复位;着色簇与导航簇纵向不重叠;整簇拖动入库;「视图 → 工具架」打开工具架并可拖动标题栏;无 `pageerror`。 +3. 回归(`--workers=1`): + - `web-area-layout.spec.ts`(2)、`web-manual-ui-gaps.spec.ts`(2)、`wbv2-panel-drag-production.spec.ts`(3)、`wbv2-adjust-last-operation-production.spec.ts`(1)、`pbr-tutorial-accessibility`(1)、`parts-tutorial-accessibility`(1)→ 全部通过。 + - A/B:`web-area-layout` + `web-manual-ui-gaps` 在 HEAD(`git stash` 掉本次全部源码改动)上 4 passed,证明失败来自本次改动,已按源码修正而非改断言。 + - `wbv2-pbr-tutorial-production.spec.ts`:`1 passed (2.2m)`(12 个步骤全部演示通过,无 `.blend` 自动下载)。 +4. 发布与线上复验: + - `BW_DEPLOY_PASSWORD=… tools/web/deploy-58014.sh` → release `20261124-workinf_blender_wasm-2c8449f42`,`health=200`、`index=200`,wasm 本地/远程哈希一致(`9febac5d…c31a2c`),`studios=200`;N 面板宽度修复后按同一 release id 重新上传切换一次(`current` 指向同一路径,`health=200`)。 + - 线上 Chromium 实走(1440×900,`https://49.232.250.35:58014/?ui=web` + `basic_scene.blend`):拖右栏分隔条 → `.properties-area` 320 → 430px,`localStorage` 记录 `rightWidth:430`;属性区「浮动为独立窗口」→ `position:fixed` → 拖标题栏 (120,70) → 位置随之变化 → 「停靠回布局」→ 浮窗记录清空;N 面板拖动入库 `{x:-2,y:50}` 且整体仍在视口内;无 `pageerror`。证据:`tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification.json`、`online-floating-properties.png`、`online-workspace-layout.png`。 + - 线上小窗口复验(1280×800,同一 release):右栏初始 290px(媒体查询默认),拖动分隔条后 320→400px 且 `localStorage` 记录 `rightWidth:400`,浮窗与 N 面板同样正常;证据 `online-verification-1280.json`。修复前该区间拖动完全无效。 + - 线上检查脚本必须沿用 `tools/web/check-deployed-web-blender.mjs` 的 Chromium 参数(含 `--enable-unsafe-webgpu --use-webgpu-adapter=swiftshader`):缺这些参数时引擎停在 “WASM: starting”,与产品无关。 + +## 未验证 / 剩余缺口 + +- 触摸/笔输入下的拖动、分隔条双指缩放未在真机验证(仅 Chromium 鼠标指针)。 +- 浮动窗口在多显示器/负坐标(`window.screenX < 0`)下的行为未验证;钳制以当前窗口为准。 +- 原生模式(`?ui=desktop` / `localOnly`)下区域由原生屏幕矩形驱动,分隔条按设计不渲染;原生模式下把区域浮动为窗口只改变显示位置,未在原生会话里实测。 +- 除 `Layout` 外的工作区使用各自固定模板(如 Modeling 的 `190px` 行),分隔条在这些工作区不渲染;这些模板是否需要同样可调,留给用户使用后决定。 +- 「恢复默认面板位置」复位面板偏移、分区尺寸与浮窗,但不复位时间线 dock 的独立位置(沿用上一批的遗留项)。 + +## 验收 + +`NOT_CLAIMED`。 diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-area.json b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-area.json new file mode 100644 index 000000000..c6fbeb8ee --- /dev/null +++ b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-area.json @@ -0,0 +1,23 @@ +{ + "schemaVersion": 1, + "browser": "chromium", + "storage": "OPFS", + "workflow": "properties area menu -> 浮动为独立窗口 -> drag title bar -> dock", + "floating": { + "position": "fixed", + "rect": { + "x": 1280, + "y": 353, + "width": 320, + "height": 627 + } + }, + "moved": { + "x": 1420, + "y": 433, + "width": 320, + "height": 627 + }, + "status": "PASS", + "acceptance": "NOT_CLAIMED" +} \ No newline at end of file diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-properties.png b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-properties.png new file mode 100644 index 000000000..c83a546b5 Binary files /dev/null and b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/floating-properties.png differ diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-floating-properties.png b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-floating-properties.png new file mode 100644 index 000000000..18f991ca7 Binary files /dev/null and b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-floating-properties.png differ diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280-floating.png b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280-floating.png new file mode 100644 index 000000000..d28b66b6d Binary files /dev/null and b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280-floating.png differ diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280.json b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280.json new file mode 100644 index 000000000..96e56a5e0 --- /dev/null +++ b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification-1280.json @@ -0,0 +1,59 @@ +{ + "schemaVersion": 1, + "browser": "chromium", + "storage": "OPFS", + "origin": "https://49.232.250.35:58014", + "workflow": "splitter drag -> properties float + move + dock -> N-panel drag (online release 20261124-workinf_blender_wasm-2c8449f42)", + "beforeProperties": { + "x": 990, + "y": 286, + "width": 290, + "height": 494 + }, + "afterProperties": { + "x": 880, + "y": 286, + "width": 400, + "height": 494 + }, + "splits": { + "rightWidth": 400, + "timelineHeight": 108, + "outlinerShare": 0.3333333333333333 + }, + "floatingPosition": "fixed", + "floatingRect": { + "x": 880, + "y": 286, + "width": 400, + "height": 494 + }, + "floatedMoved": { + "x": 1000, + "y": 356, + "width": 400, + "height": 494 + }, + "dockedFloating": 0, + "viewportRect": { + "x": 0, + "y": 93, + "width": 879, + "height": 578 + }, + "sidebarRect": { + "x": 470, + "y": 411, + "width": 407, + "height": 258 + }, + "offsets": { + "viewport-n-panel": { + "x": -2, + "y": 6 + } + }, + "pageErrors": [], + "status": "PASS", + "acceptance": "NOT_CLAIMED" +} \ No newline at end of file diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification.json b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification.json new file mode 100644 index 000000000..81da8ddba --- /dev/null +++ b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-verification.json @@ -0,0 +1,59 @@ +{ + "schemaVersion": 1, + "browser": "chromium", + "storage": "OPFS", + "origin": "https://49.232.250.35:58014", + "workflow": "splitter drag -> properties float + move + dock -> N-panel drag (online release 20261124-workinf_blender_wasm-2c8449f42)", + "beforeProperties": { + "x": 1120, + "y": 320, + "width": 320, + "height": 560 + }, + "afterProperties": { + "x": 1010, + "y": 320, + "width": 430, + "height": 560 + }, + "splits": { + "rightWidth": 430, + "timelineHeight": 108, + "outlinerShare": 0.3333333333333333 + }, + "floatingPosition": "fixed", + "floatingRect": { + "x": 1010, + "y": 320, + "width": 430, + "height": 560 + }, + "floatedMoved": { + "x": 1130, + "y": 390, + "width": 430, + "height": 560 + }, + "dockedFloating": 0, + "viewportRect": { + "x": 0, + "y": 93, + "width": 1009, + "height": 678 + }, + "sidebarRect": { + "x": 600, + "y": 455, + "width": 407, + "height": 293 + }, + "offsets": { + "viewport-n-panel": { + "x": -2, + "y": 50 + } + }, + "pageErrors": [], + "status": "PASS", + "acceptance": "NOT_CLAIMED" +} \ No newline at end of file diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-workspace-layout.png b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-workspace-layout.png new file mode 100644 index 000000000..d0ab4aa33 Binary files /dev/null and b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/online-workspace-layout.png differ diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/splits.json b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/splits.json new file mode 100644 index 000000000..001d96b85 --- /dev/null +++ b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/splits.json @@ -0,0 +1,51 @@ +{ + "schemaVersion": 1, + "browser": "chromium", + "storage": "OPFS", + "workflow": "/?ui=web + basic_scene.blend -> drag right/timeline splitters -> reload -> ArrowRight -> double-click reset", + "before": { + "viewport": { + "x": 0, + "y": 93, + "width": 1279, + "height": 778 + }, + "properties": { + "x": 1280, + "y": 353, + "width": 320, + "height": 627 + }, + "timeline": { + "x": 0, + "y": 872, + "width": 1279, + "height": 108 + } + }, + "widened": { + "x": 1160, + "y": 353, + "width": 440, + "height": 627 + }, + "taller": { + "x": 0, + "y": 832, + "width": 1159, + "height": 148 + }, + "reloaded": { + "x": 1160, + "y": 339.65625, + "width": 440, + "height": 640.34375 + }, + "splits": { + "rightWidth": 320, + "timelineHeight": 108, + "outlinerShare": 0.3333333333333333 + }, + "status": "PASS", + "acceptance": "NOT_CLAIMED" +} \ No newline at end of file diff --git a/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/viewport-overlays.json b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/viewport-overlays.json new file mode 100644 index 000000000..f8107be2c --- /dev/null +++ b/tests/golden/WEB-WORKSPACE-LAYOUT-20261123/viewport-overlays.json @@ -0,0 +1,53 @@ +{ + "schemaVersion": 1, + "browser": "chromium", + "storage": "OPFS", + "workflow": "drag N-panel -> close/reopen with N -> reset -> drag quick tools -> T shelf -> drag header", + "viewportRect": { + "x": 0, + "y": 93, + "width": 1279, + "height": 778 + }, + "movedSidebar": { + "x": 870, + "y": 465, + "width": 407, + "height": 293 + }, + "movedQuick": { + "x": 1102.9375, + "y": 221, + "width": 34.0625, + "height": 354 + }, + "shading": { + "x": 1229, + "y": 209, + "width": 28, + "height": 61 + }, + "navigation": { + "x": 1229, + "y": 276, + "width": 28, + "height": 259 + }, + "offsets": { + "sidebar": { + "x": 0, + "y": 0 + }, + "quick": { + "x": -120, + "y": 40 + }, + "shelf": { + "x": 40, + "y": 2 + } + }, + "pageErrors": [], + "status": "PASS", + "acceptance": "NOT_CLAIMED" +} \ No newline at end of file diff --git a/web/app/src/app/App.tsx b/web/app/src/app/App.tsx index e2eb92a7e..b6d290424 100644 --- a/web/app/src/app/App.tsx +++ b/web/app/src/app/App.tsx @@ -14,6 +14,7 @@ import {recoverDesktop,saveDesktop} from './desktop-workspace-storage'; import {NativeResourceClient} from '../engine-client/NativeResourceClient'; import { COURSES, type AvailableCourseId } from "../tutorial/course"; import { resetAllPanelOffsets, useDraggablePanel } from "./use-draggable-panel"; +import { resetWorkspaceLayout, useWorkspaceLayout } from "./workspace-layout"; import { TutorialOverlay } from "../tutorial/TutorialOverlay"; import type { PbrCameraMode, PbrResolution, TutorialApi, TutorialContext, TutorialRenderResult } from "../tutorial/parts/types"; import type {NativeExportFormat} from '../../../protocol/native-workflow'; @@ -49,7 +50,7 @@ import type {NativeSessionCommand} from '../../../protocol/native-workflow'; import type { NativeWorkflowContext, NativeWorkflowInput } from '../../../protocol/native-workflow'; -import { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from "react"; +import { createContext, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, type PointerEvent as ReactPointerEvent } from "react"; import { createPortal, flushSync } from "react-dom"; import { WebEngineClient, type BlendOpenResult } from "../engine-client/WebEngineClient"; import {runEmbeddedRender} from '../engine-client/embedded-render'; @@ -1282,6 +1283,8 @@ const AREA_EDITOR_CHOICES: EditorType[] = [ ]; interface AreaEditorContextValue { + /** Current workspace; decides whether an area's header is displayed. */ + workspace: WorkspaceId; overrides: Record; setOverride: (areaKey: string, editor: EditorType | null) => void; render: (editor: EditorType, areaKey: string) => React.ReactNode; @@ -1293,6 +1296,9 @@ interface AreaEditorContextValue { resetLayout: () => void; } const AreaEditorContext = createContext(null); +/** Areas whose `.editor-header` is hidden by app-shell.css in every workspace. */ +const AREA_HEADERLESS = new Set(["image-editor-area", "render-result-area", "node-editor-area", "file-browser-area", + "spreadsheet-area", "text-editor-area", "console-area", "info-area"]); function activeViewportCanvas():HTMLCanvasElement|null { return document.querySelector('canvas.viewport-canvas:focus') ?? @@ -1324,6 +1330,9 @@ const EDITOR_ICONS: Record = { function Area({ className = "", editor, children, areaId }: AreaProps) { const context = useContext(AreaEditorContext); + const workspaceLayout = useWorkspaceLayout(); + const floatDrag = useRef<{ pointerId: number; startX: number; startY: number; originX: number; originY: number } | null>(null); + const floatResize = useRef<{ pointerId: number; startX: number; startY: number; startW: number; startH: number } | null>(null); const areaKey = areaId ?? (className || editor); const layout = context?.layoutFor(areaKey) ?? null; const activeDefault = layout?.editor ?? editor; @@ -1333,13 +1342,56 @@ function Area({ className = "", editor, children, areaId }: AreaProps) { if (custom && !layout) return null; if (custom && layout && !layout.maximized && context?.areas.some((area) => area.maximized)) return null; const rect = layout?.rect; - const style = custom && layout?.maximized ? { left: "0%", top: "0%", width: "100%", height: "100%" } : custom && rect ? { + const targetId = layout?.id ?? areaKey; + /* An area can be pulled out of the grid into its own floating window. It is + * the same React section, only re-positioned, so the WebGL canvas, text + * drafts and scroll positions are never remounted. */ + const floatRect = workspaceLayout.state.floating[targetId] ?? null; + /* Mirrors the `editor-header { display: none }` rules in app-shell.css: areas + * without a header keep the floating editor switcher, the rest carry it in + * the header so it cannot sit on top of the header's own buttons. */ + const headerHidden = !floatRect && (AREA_HEADERLESS.has(className) || + ((className === "viewport-area" || className === "timeline-area") && context?.workspace !== "Scripting")); + const style = floatRect ? { position: "fixed" as const, left: `${floatRect.x}px`, top: `${floatRect.y}px`, width: `${floatRect.width}px`, height: `${floatRect.height}px`, zIndex: 70 } : custom && layout?.maximized ? { left: "0%", top: "0%", width: "100%", height: "100%" } : custom && rect ? { left: `${rect.x * 100}%`, top: `${(1 - rect.y - rect.height) * 100}%`, width: `${rect.width * 100}%`, height: `${rect.height * 100}%`, } : undefined; - const targetId = layout?.id ?? areaKey; + const floatNow = () => { + const node = document.querySelector(`[data-web-area-id="${targetId}"]`); + const current = node?.getBoundingClientRect(); + workspaceLayout.floatArea(targetId, current + ? { x: Math.round(current.left), y: Math.round(current.top), width: Math.round(current.width), height: Math.round(current.height) } + : { x: 80, y: 80, width: 720, height: 480 }); + }; + const startFloatDrag = (event: ReactPointerEvent) => { + if (event.button !== 0 || !floatRect) return; + if ((event.target as HTMLElement).closest("button, select, .desktop-menu-trigger")) return; + floatDrag.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, originX: floatRect.x, originY: floatRect.y }; + event.currentTarget.setPointerCapture(event.pointerId); + }; + const moveFloatDrag = (event: ReactPointerEvent) => { + const drag = floatDrag.current; + if (!drag || drag.pointerId !== event.pointerId || !floatRect) return; + /* Keep part of the title bar reachable, like the other floating panels. */ + const x = Math.round(Math.min(Math.max(drag.originX + event.clientX - drag.startX, 64 - floatRect.width / 2), window.innerWidth - 160)); + const y = Math.round(Math.min(Math.max(drag.originY + event.clientY - drag.startY, 0), window.innerHeight - 60)); + workspaceLayout.moveFloating(targetId, { x, y, width: floatRect.width, height: floatRect.height }); + }; + const endFloatDrag = (event: ReactPointerEvent) => { + if (floatDrag.current?.pointerId !== event.pointerId && floatResize.current?.pointerId !== event.pointerId) return; + floatDrag.current = null; + floatResize.current = null; + if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId); + }; + const moveFloatResize = (event: ReactPointerEvent) => { + const drag = floatResize.current; + if (!drag || drag.pointerId !== event.pointerId || !floatRect) return; + const width = Math.round(Math.min(Math.max(drag.startW + event.clientX - drag.startX, 240), window.innerWidth - floatRect.x)); + const height = Math.round(Math.min(Math.max(drag.startH + event.clientY - drag.startY, 160), window.innerHeight - floatRect.y)); + workspaceLayout.moveFloating(targetId, { x: floatRect.x, y: floatRect.y, width, height }); + }; const neighbors = context?.neighbors(targetId) ?? { LEFT: null, RIGHT: null, UP: null, DOWN: null }; const directionLabel: Record = { LEFT: "左", RIGHT: "右", UP: "上", DOWN: "下" }; const areaMenuItems: DesktopMenuItem[] = context ? [ @@ -1360,44 +1412,59 @@ function Area({ className = "", editor, children, areaId }: AreaProps) { { label: "", separator: true }, { label: layout?.maximized ? "还原大小" : "最大化区域", action: () => context.dispatchArea(targetId, { type: "TOGGLE_MAXIMIZE_AREA", areaId: targetId }) }, { label: "聚焦模式", action: () => context.dispatchArea(targetId, { type: "TOGGLE_FULLSCREEN_AREA", areaId: targetId }) }, + { label: floatRect ? "停靠回布局" : "浮动为独立窗口", action: () => { if (floatRect) workspaceLayout.dockArea(targetId); else floatNow(); } }, { label: "关闭区域", disabled: context.areas.length <= 1, reason: "至少保留一个区域", action: () => context.dispatchArea(targetId, { type: "CLOSE_AREA", areaId: targetId }) }, { label: "", separator: true }, { label: "重置工作区布局", action: () => context.resetLayout() }, ] : []; const newAreaContent = children === undefined && context ? context.render(activeEditor, areaKey) : children; const useDefaultContent = override ? false : layout ? (layout.editor === editor && children !== undefined) : children !== undefined; + /* One editor switcher per area: it lives in the header where there is one, + * and floats over the content only where the header is hidden. */ + const switcher = (className || areaId) && context ? ( +
+ + + +
+ ) : null; return ( + <> + {floatRect && !custom ?
: null}
- {(className || areaId) && context ? ( -
- - - -
- ) : null} -
+ {headerHidden ? switcher : null} + {headerHidden ? null :
+ {floatRect ? : null} - -
+ {floatRect ? : null} + {switcher ?? } +
}
{useDefaultContent ? newAreaContent : context!.render(activeEditor, areaKey)}
+ {floatRect ? { if (event.button !== 0 || !floatRect) return; floatResize.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, startW: floatRect.width, startH: floatRect.height }; event.currentTarget.setPointerCapture(event.pointerId); }} + onPointerMove={moveFloatResize} onPointerUp={endFloatDrag} onPointerCancel={endFloatDrag} /> : null}
+ ); } @@ -1709,6 +1776,27 @@ function ViewportPlaceholder({ snapshot, geometryBuffers, nonMeshGeometryBuffers * region toggles (wm.context_toggle space_data.show_region_*). */ const [toolShelfOpen, setToolShelfOpen] = useState(false); const [sidePanelOpen, setSidePanelOpen] = useState(true); + /* Viewport overlays: keep them inside the viewport box, which clips overflow. */ + const viewportOverlayBounds = (panel: HTMLElement) => { + const host = panel.closest(".viewport-placeholder"); + if (!host) return null; + const rect = host.getBoundingClientRect(); + return { left: rect.left + 2, top: rect.top + 2, right: rect.right - 2, bottom: rect.bottom - 2 }; + }; + const toolShelfDrag = useDraggablePanel("viewport-tool-shelf", { bounds: viewportOverlayBounds }); + const sidePanelDrag = useDraggablePanel("viewport-n-panel", { bounds: viewportOverlayBounds }); + const quickToolsDrag = useDraggablePanel("viewport-quick-tools", { bounds: viewportOverlayBounds }); + const overlayDragStyle = (offset: { x: number; y: number }) => offset.x || offset.y ? { transform: `translate(${offset.x}px, ${offset.y}px)` } : undefined; + /* 视图 → 侧栏 / 工具架: the menus live in App, the visibility state here. */ + useEffect(() => { + const onToggle = (event: Event) => { + const kind = (event as CustomEvent).detail; + if (kind === "side-panel") setSidePanelOpen(open => !open); + else if (kind === "tool-shelf") setToolShelfOpen(open => !open); + }; + window.addEventListener("web-blender:viewport-overlay-toggle", onToggle); + return () => window.removeEventListener("web-blender:viewport-overlay-toggle", onToggle); + }, []); const cycleShadingModeRef = useRef<() => void>(() => {}); const shadingModeRef = useRef<"WIREFRAME" | "SOLID" | "MATERIAL" | "RENDERED">("MATERIAL"); const xrayRef = useRef(false); @@ -2084,6 +2172,8 @@ function ViewportPlaceholder({ snapshot, geometryBuffers, nonMeshGeometryBuffers return ; })} ; })()} +
+
@@ -2097,12 +2187,13 @@ function ViewportPlaceholder({ snapshot, geometryBuffers, nonMeshGeometryBuffers
+
{viewportError ?
3D ViewportWebGL 不可用,已保留场景编辑界面:{viewportError}
: null} {editMode && activeTool === "marquee" && marqueeDrawing ?
{marqueeBox ? : null}
: null} {activeTool === "box" && snapshot ?
{boxSelectRect ? : null}
: null} {brushCursor ? : null} -