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.

feat(editor): per-panel collapse chevron in dock headers

esengine109665e1b8a5
diff --git a/desktop/src/layout/DockLayout.tsx b/desktop/src/layout/DockLayout.tsx
index 3c492127d..170f58c2f 100644
--- a/desktop/src/layout/DockLayout.tsx
+++ b/desktop/src/layout/DockLayout.tsx
@@ -1,5 +1,11 @@
-import type { FC } from 'react';
-import { DockviewReact, type DockviewReadyEvent, type IDockviewPanelProps } from 'dockview';
+import { useEffect, useState, type FC } from 'react';
+import {
+ DockviewReact,
+ type DockviewReadyEvent,
+ type IDockviewPanelProps,
+ type IDockviewHeaderActionsProps,
+} from 'dockview';
+import { ChevronDown } from 'lucide-react';
import { Outliner } from '@/panels/Outliner';
import { Viewport } from '@/panels/Viewport';
import { Details } from '@/panels/Details';
@@ -61,6 +67,32 @@ function buildDefaultLayout(api: DockviewReadyEvent['api']) {
});
}
+// A collapse/expand chevron in every dock group's header (the design's `.pcol`).
+// Collapses the group to its tab bar by height; hidden on the Viewport/Game group
+// (the center stage isn't an accordion). State follows the live group height, so
+// it stays correct after splitter drags and layout restores.
+function CollapseHeaderAction(props: IDockviewHeaderActionsProps) {
+ const collapsible = !props.panels.some((p) => p.id === 'viewport' || p.id === 'game');
+ const [collapsed, setCollapsed] = useState(() => dockApi.groupCollapsed(props.api));
+ useEffect(() => {
+ const d = props.api.onDidDimensionsChange(() => setCollapsed(dockApi.groupCollapsed(props.api)));
+ return () => d.dispose();
+ }, [props.api]);
+ if (!collapsible) return null;
+ return (
+ <button
+ type="button"
+ className="dv-collapse"
+ title={collapsed ? 'Expand panel' : 'Collapse panel'}
+ aria-label={collapsed ? 'Expand panel' : 'Collapse panel'}
+ aria-expanded={!collapsed}
+ onClick={() => dockApi.setGroupCollapsed(props.api, props.group.id, !collapsed)}
+ >
+ <ChevronDown size={14} strokeWidth={2} className={collapsed ? 'is-collapsed' : ''} />
+ </button>
+ );
+}
+
export function DockLayout() {
const onReady = (event: DockviewReadyEvent) => {
const { api } = event;
@@ -88,6 +120,7 @@ export function DockLayout() {
<DockviewReact
className="dockview-theme-abyss dockview-theme-estella"
components={components}
+ rightHeaderActionsComponent={CollapseHeaderAction}
onReady={onReady}
/>
);
diff --git a/desktop/src/layout/dockApi.ts b/desktop/src/layout/dockApi.ts
index 4fa8a7571..2fff3282c 100644
--- a/desktop/src/layout/dockApi.ts
+++ b/desktop/src/layout/dockApi.ts
@@ -4,12 +4,21 @@
* bar) can reveal/focus docked panels without threading the api through
* React. DockLayout sets it on ready; callers guard against null.
*/
-import type { DockviewApi } from 'dockview';
+import type { DockviewApi, DockviewGroupPanelApi } from 'dockview';
let api: DockviewApi | null = null;
// Remembered pre-collapse sizes, per panel id (so a re-expand restores them).
const sizes = new Map<string, number>();
+// Per-panel header collapse (the design's `.pcol` accordion): a dock group is
+// shrunk to its tab-bar height so only the header shows, then restored. dockview's
+// native group.collapse() is edge-groups-only (ours are grid groups), so we drive
+// it by locking the group's height constraint to the header height. Collapse is by
+// HEIGHT — every collapsible panel sits in a vertically-split, horizontal-tab group.
+const COLLAPSED_H = 32; // collapsed group height ≈ the tab strip (--h-tab)
+const EXPAND_FALLBACK = 240; // restore height when the pre-collapse size is unknown
+const collapsedPrev = new Map<string, number>();
+
export const dockApi = {
set(next: DockviewApi | null) {
api = next;
@@ -48,4 +57,27 @@ export const dockApi = {
panel.api.setSize(axis === 'width' ? { width: 0 } : { height: 0 });
}
},
+
+ /** True when a dock group is shrunk to (around) its header/tab-bar height. */
+ groupCollapsed(groupApi: DockviewGroupPanelApi): boolean {
+ return groupApi.height <= COLLAPSED_H + 8;
+ },
+
+ /**
+ * Collapse a dock group to its header bar (or expand it back), by height —
+ * the per-panel accordion the header chevron drives. Locks the group's height
+ * constraint while collapsed so the splitter can't drag it half-open; only the
+ * chevron expands it (restoring the remembered pre-collapse height).
+ */
+ setGroupCollapsed(groupApi: DockviewGroupPanelApi, groupId: string, collapsed: boolean) {
+ if (collapsed) {
+ if (groupApi.height > COLLAPSED_H + 8) collapsedPrev.set(groupId, groupApi.height);
+ groupApi.setConstraints({ minimumHeight: COLLAPSED_H, maximumHeight: COLLAPSED_H });
+ groupApi.setSize({ height: COLLAPSED_H });
+ } else {
+ groupApi.setConstraints({ minimumHeight: 60, maximumHeight: Number.MAX_SAFE_INTEGER });
+ groupApi.setSize({ height: collapsedPrev.get(groupId) ?? EXPAND_FALLBACK });
+ collapsedPrev.delete(groupId);
+ }
+ },
};
diff --git a/desktop/src/theme/dockview-theme.css b/desktop/src/theme/dockview-theme.css
index a9fd1c9ec..d9a39ac71 100644
--- a/desktop/src/theme/dockview-theme.css
+++ b/desktop/src/theme/dockview-theme.css
@@ -98,3 +98,23 @@
background: var(--srf-2);
z-index: 1;
}
+
+/* Per-panel collapse chevron in the group header (rightHeaderActionsComponent) —
+ the design's `.pcol`. Collapses the panel to its tab bar; rotates when collapsed. */
+.dockview-theme-estella .dv-collapse {
+ display: grid;
+ place-items: center;
+ width: 26px;
+ height: 100%;
+ color: var(--text-mute);
+ transition: color var(--t-fast);
+}
+.dockview-theme-estella .dv-collapse:hover {
+ color: var(--text);
+}
+.dockview-theme-estella .dv-collapse svg {
+ transition: transform var(--t-fast) var(--e-out);
+}
+.dockview-theme-estella .dv-collapse svg.is-collapsed {
+ transform: rotate(180deg);
+}