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.

refactor(editor): NumField + panel-header scaffolding go shared

yhh7ffb0c796d82
diff --git a/desktop/src/components/NumField.tsx b/desktop/src/components/NumField.tsx
new file mode 100644
index 000000000..73eec9040
--- /dev/null
+++ b/desktop/src/components/NumField.tsx
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file NumField.tsx
+ * @brief The shared numeric input + drag-scrub gesture. The field itself is a
+ * plain click-to-type box (live-commit while typing); the scrub
+ * affordance lives on whatever LABEL the caller attaches `useScrub` to
+ * (the inspector's property label / colored axis tab), so the two stay
+ * composable. Styling is the `.field` well in theme/controls.css.
+ */
+import { useRef, useState } from 'react';
+
+/** Numbers render with float noise rounded away (3 decimal places). */
+export const fmt = (n: number) => String(Math.round(n * 1000) / 1000);
+
+// Each control reports gesture boundaries (onBegin/onEnd) so one focus→blur, one
+// click, or one drag-scrub becomes a single undo step; onCommit applies live.
+export interface ControlGesture {
+ onBegin?: () => void;
+ onEnd?: () => void;
+}
+
+export interface ScrubOpts extends ControlGesture {
+ /** Units per pixel of drag (default 0.1); Shift = ÷10, Alt = ×10. */
+ step?: number;
+ min?: number;
+ max?: number;
+}
+
+// Drag-to-scrub. The affordance lives on the property LABEL (scalars) or the
+// colored axis TAB (vectors) — NOT the input — so the field stays a plain
+// click-to-type box. Press + drag horizontally to nudge; a press under the 3px
+// threshold is ignored. The result clamps to [min,max] when the field is ranged.
+export function useScrub(value: number, onCommit: (n: number) => void, opts: ScrubOpts = {}) {
+ const scrub = useRef<{ x: number; base: number; moved: boolean } | null>(null);
+ return {
+ onPointerDown: (e: React.PointerEvent) => {
+ if (e.button !== 0) return;
+ e.preventDefault();
+ scrub.current = { x: e.clientX, base: value, moved: false };
+ e.currentTarget.setPointerCapture(e.pointerId);
+ },
+ onPointerMove: (e: React.PointerEvent) => {
+ const s = scrub.current;
+ if (!s) return;
+ const dx = e.clientX - s.x;
+ if (!s.moved) {
+ if (Math.abs(dx) < 3) return;
+ s.moved = true;
+ opts.onBegin?.();
+ }
+ const base = opts.step ?? 0.1;
+ const step = e.shiftKey ? base / 10 : e.altKey ? base * 10 : base;
+ let next = Math.round((s.base + dx * step) * 1000) / 1000;
+ if (opts.min != null) next = Math.max(opts.min, next);
+ if (opts.max != null) next = Math.min(opts.max, next);
+ onCommit(next);
+ },
+ onPointerUp: (e: React.PointerEvent) => {
+ const s = scrub.current;
+ scrub.current = null;
+ if (!s) return;
+ e.currentTarget.releasePointerCapture?.(e.pointerId);
+ if (s.moved) opts.onEnd?.();
+ },
+ };
+}
+
+// Plain click-to-type numeric input. `suffix` (e.g. °) shows in the resting value;
+// `mixed` (multi-select disagreement) shows a "—" placeholder until typed over.
+export function NumField({
+ value,
+ suffix,
+ mixed,
+ onBegin,
+ onEnd,
+ onCommit,
+}: ControlGesture & { value: number; suffix?: string; mixed?: boolean; onCommit: (n: number) => void }) {
+ const [editing, setEditing] = useState(false);
+ const [text, setText] = useState('');
+ return (
+ <span className="field">
+ <input
+ value={editing ? text : mixed ? '' : fmt(value) + (suffix ?? '')}
+ placeholder={mixed ? '—' : undefined}
+ spellCheck={false}
+ onFocus={() => {
+ setText(fmt(value));
+ setEditing(true);
+ onBegin?.();
+ }}
+ onBlur={() => {
+ setEditing(false);
+ onEnd?.();
+ }}
+ onChange={(e) => {
+ setText(e.target.value);
+ const n = parseFloat(e.target.value);
+ if (!Number.isNaN(n)) onCommit(n);
+ }}
+ />
+ </span>
+ );
+}
diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsx
index a2dd36389..ee2dd2763 100644
--- a/desktop/src/panels/ContentBrowser.tsx
+++ b/desktop/src/panels/ContentBrowser.tsx
@@ -822,7 +822,7 @@ export function ContentBrowser() {
<div className="cb-work">
{/* ── Sources (left) ── */}
<div className="cb-panel cb-src">
- <div className="cb-head">
+ <div className="phead cb-head">
<span className="pt">Sources</span>
</div>
<div className="cb-src-body">
@@ -833,7 +833,7 @@ export function ContentBrowser() {
{/* ── Main (center) ── */}
<div className="cb-panel cb-main">
- <div className="cb-bar">
+ <div className="phead cb-bar">
<div className="cb-nav">
<button type="button" disabled={!canBack} onClick={back} title="Back">
<ArrowLeft size={15} strokeWidth={2} />
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 3f682ca39..dfb5a1274 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -61,6 +61,7 @@ import {
type MaterialContext,
} from '@/material/materialInspectorModel';
import { ContextMenu } from '@/components/Menu';
+import { NumField, useScrub, fmt, type ControlGesture } from '@/components/NumField';
import { Popover, usePopover } from '@/components/Popover';
import { SearchField } from '@/components/SearchField';
import { Select } from '@/components/Select';
@@ -68,7 +69,6 @@ import { AddComponentMenu } from '@/components/AddComponentMenu';
import type { InspectorComponent, InspectorField, InspectorFieldValue, EntityId, NodeKind, EnumOption, AssetType, GradientValue, GradientStop, CurveValue, CurveKey, DimensionValue } from '@/types';
const AXES = ['x', 'y', 'z'];
-const fmt = (n: number) => String(Math.round(n * 1000) / 1000);
// Field-value equality for the "modified" (override) mark. Vectors compare
// element-wise; numbers tolerate float drift so a no-op edit doesn't read as one.
@@ -110,95 +110,8 @@ const KIND_LABEL: Record<NodeKind, string> = {
empty: 'Entity',
};
-// Each control reports gesture boundaries (onBegin/onEnd) so one focus→blur, one
-// click, or one drag-scrub becomes a single undo step; onCommit applies live.
-export interface ControlGesture {
- onBegin?: () => void;
- onEnd?: () => void;
-}
-
-interface ScrubOpts extends ControlGesture {
- /** Units per pixel of drag (default 0.1); Shift = ÷10, Alt = ×10. */
- step?: number;
- min?: number;
- max?: number;
-}
-
-// Drag-to-scrub. The affordance lives on the property LABEL (scalars) or the
-// colored axis TAB (vectors) — NOT the input — so the field stays a plain
-// click-to-type box. Press + drag horizontally to nudge; a press under the 3px
-// threshold is ignored. The result clamps to [min,max] when the field is ranged.
-function useScrub(value: number, onCommit: (n: number) => void, opts: ScrubOpts = {}) {
- const scrub = useRef<{ x: number; base: number; moved: boolean } | null>(null);
- return {
- onPointerDown: (e: React.PointerEvent) => {
- if (e.button !== 0) return;
- e.preventDefault();
- scrub.current = { x: e.clientX, base: value, moved: false };
- e.currentTarget.setPointerCapture(e.pointerId);
- },
- onPointerMove: (e: React.PointerEvent) => {
- const s = scrub.current;
- if (!s) return;
- const dx = e.clientX - s.x;
- if (!s.moved) {
- if (Math.abs(dx) < 3) return;
- s.moved = true;
- opts.onBegin?.();
- }
- const base = opts.step ?? 0.1;
- const step = e.shiftKey ? base / 10 : e.altKey ? base * 10 : base;
- let next = Math.round((s.base + dx * step) * 1000) / 1000;
- if (opts.min != null) next = Math.max(opts.min, next);
- if (opts.max != null) next = Math.min(opts.max, next);
- onCommit(next);
- },
- onPointerUp: (e: React.PointerEvent) => {
- const s = scrub.current;
- scrub.current = null;
- if (!s) return;
- e.currentTarget.releasePointerCapture?.(e.pointerId);
- if (s.moved) opts.onEnd?.();
- },
- };
-}
-
-// Plain click-to-type numeric input. `suffix` (e.g. °) shows in the resting value;
-// `mixed` (multi-select disagreement) shows a "—" placeholder until typed over.
-export function NumField({
- value,
- suffix,
- mixed,
- onBegin,
- onEnd,
- onCommit,
-}: ControlGesture & { value: number; suffix?: string; mixed?: boolean; onCommit: (n: number) => void }) {
- const [editing, setEditing] = useState(false);
- const [text, setText] = useState('');
- return (
- <span className="field">
- <input
- value={editing ? text : mixed ? '' : fmt(value) + (suffix ?? '')}
- placeholder={mixed ? '—' : undefined}
- spellCheck={false}
- onFocus={() => {
- setText(fmt(value));
- setEditing(true);
- onBegin?.();
- }}
- onBlur={() => {
- setEditing(false);
- onEnd?.();
- }}
- onChange={(e) => {
- setText(e.target.value);
- const n = parseFloat(e.target.value);
- if (!Number.isNaN(n)) onCommit(n);
- }}
- />
- </span>
- );
-}
+// The gesture contract, scrub hook, and NumField are the shared numeric-input
+// primitives (components/NumField.tsx); the inspector composes them below.
// One vector component — the colored X/Y/Z tab IS the scrub handle.
function VecField({
@@ -2049,7 +1962,7 @@ function EditorDetails() {
return (
<div className="insp">
- <div className="insp-head">
+ <div className="phead insp-head">
<SearchField placeholder="Search" value={query} onChange={setQuery} />
<button
type="button"
diff --git a/desktop/src/panels/MaterialGraphEditor.tsx b/desktop/src/panels/MaterialGraphEditor.tsx
index 9c2606bb6..9fd4d9660 100644
--- a/desktop/src/panels/MaterialGraphEditor.tsx
+++ b/desktop/src/panels/MaterialGraphEditor.tsx
@@ -29,8 +29,9 @@ import {
import { MaterialGraphDocument } from '@/material/MaterialGraphDocument';
import { saveMaterialGraph } from '@/material/openMaterialGraph';
import { EditorHistory } from '@/engine/EditorHistory';
-import { NumField, ColorControl } from '@/panels/Details';
+import { ColorControl } from '@/panels/Details';
import { DirtyDot } from '@/components/DirtyDot';
+import { NumField } from '@/components/NumField';
import {
NodeGraphCanvas,
type CanvasEdge,
diff --git a/desktop/src/panels/Sequencer.tsx b/desktop/src/panels/Sequencer.tsx
index eb86103fa..02a5f615f 100644
--- a/desktop/src/panels/Sequencer.tsx
+++ b/desktop/src/panels/Sequencer.tsx
@@ -27,6 +27,7 @@ import { useSelection } from '@/store/selectionStore';
import { SceneModel } from '@/engine/SceneModel';
import { ContextMenu, type MenuItem } from '@/components/Menu';
import { DirtyDot } from '@/components/DirtyDot';
+import { NumField } from '@/components/NumField';
import { SequencerCurve } from '@/panels/SequencerCurve';
import {
buildTimelineRows, visibleRows, frameCount, timeToPct, pctToTime, findChannel, muteKey,
@@ -341,7 +342,7 @@ function SequencerBody() {
onKeyDown={onPanelKey}
>
{/* transport */}
- <div className="seq-bar">
+ <div className="phead seq-bar">
<span className="seq-meta">
<Film size={13} className="seq-meta__icon" />
<b>{TimelineDocument.meta.filePath?.split('/').pop() ?? 'Unnamed'}</b>
@@ -541,17 +542,11 @@ function SequencerBody() {
<div className="seq-interp__title">Clip settings</div>
<label className="seq-settings__row">
<span>Duration (s)</span>
- <input
- type="number" min={0} step={0.1} defaultValue={duration}
- onChange={(e) => TimelineCommands.setDuration(parseFloat(e.target.value) || 0)}
- />
+ <NumField value={duration} onCommit={(n) => TimelineCommands.setDuration(Math.max(0, n))} />
</label>
<label className="seq-settings__row">
<span>Frame rate (fps)</span>
- <input
- type="number" min={1} step={1} defaultValue={fps}
- onChange={(e) => TimelineDocument.setFps(parseInt(e.target.value, 10) || 1)}
- />
+ <NumField value={fps} onCommit={(n) => TimelineDocument.setFps(Math.max(1, Math.round(n)))} />
</label>
<div className="seq-settings__row">
<span>Loop</span>
diff --git a/desktop/src/theme/content.css b/desktop/src/theme/content.css
index 3d2e4af45..d374d422e 100644
--- a/desktop/src/theme/content.css
+++ b/desktop/src/theme/content.css
@@ -8,7 +8,8 @@
.cb-work { flex: 1; display: flex; min-height: 0; background: var(--srf-0); }
.cb-panel { display: flex; flex-direction: column; min-height: 0; background: var(--srf-2); }
-.cb-head { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 10px; background: var(--srf-3); border-bottom: 1px solid var(--border); flex-shrink: 0; }
+/* shared .phead + column-header face */
+.cb-head { height: 30px; padding: 0 6px 0 10px; background: var(--srf-3); }
.cb-head .pt { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.cb-head .sp { flex: 1; }
.cb-ico { width: 22px; height: 22px; display: grid; place-items: center; color: var(--text-mute); border-radius: var(--r-sm); transition: color var(--t-fast), background var(--t-fast); }
@@ -33,7 +34,8 @@
/* ── Main (center) ── */
.cb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
-.cb-bar { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--srf-2); }
+/* shared .phead, toolbar-height */
+.cb-bar { height: 38px; padding: 0 10px; background: var(--srf-2); }
.cb-nav { display: flex; gap: 1px; }
.cb-nav button { width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-dim); border-radius: var(--r-sm); transition: color var(--t-fast), background var(--t-fast); }
.cb-nav button:hover:not(:disabled) { color: var(--text); background: var(--srf-4); }
diff --git a/desktop/src/theme/controls.css b/desktop/src/theme/controls.css
index 61f805a3b..99b8200e3 100644
--- a/desktop/src/theme/controls.css
+++ b/desktop/src/theme/controls.css
@@ -55,6 +55,42 @@
.sel-trigger > svg { color: var(--text-mute); flex-shrink: 0; }
.sel-trigger .dd-val { flex: 1; }
+/* — Panel header scaffolding: the fixed-height search/actions row atop a
+ docked panel, its icon buttons, and the scrolling body under it. Panels
+ keep only height/background deltas (30–38px is deliberate per panel). — */
+.phead {
+ height: 32px;
+ flex-shrink: 0;
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 0 8px;
+ border-bottom: 1px solid var(--border);
+}
+.pbtn {
+ width: 24px;
+ height: 24px;
+ display: grid;
+ place-items: center;
+ color: var(--text-mute);
+ border-radius: var(--r-sm);
+ flex-shrink: 0;
+ transition: color var(--t-fast), background var(--t-fast);
+}
+.pbtn:hover { color: var(--text); background: var(--srf-4); }
+.pbtn:active { background: var(--srf-5); }
+.pbtn:disabled { opacity: 0.4; cursor: default; }
+.pbtn.on { color: var(--acc); }
+.pbody { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
+
+/* — Input well (components/NumField.tsx + the inspector's dropdown trigger):
+ a bordered inset the actual control sits in, focus ring on the well. — */
+.field { height: 22px; flex: 1; min-width: 0; display: flex; align-items: center; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
+.field:focus-within { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }
+.field input { width: 100%; min-width: 0; background: none; border: none; outline: none; padding: 0 7px; font-size: var(--fs-sm); color: var(--text); font-family: var(--mono); }
+.field select { width: 100%; background: none; border: none; outline: none; padding: 0 6px; font-size: var(--fs-sm); color: var(--text); appearance: none; cursor: pointer; }
+.field.dropdown { padding: 0; overflow: hidden; }
+
/* — Search/filter field (components/SearchField.tsx). One recipe for every
panel filter; usage sites keep only layout deltas (width/height/margin).
The flush variant is the popover-internal border-bottom row. — */
diff --git a/desktop/src/theme/inspector.css b/desktop/src/theme/inspector.css
index 0791a79af..6ed2410dc 100644
--- a/desktop/src/theme/inspector.css
+++ b/desktop/src/theme/inspector.css
@@ -10,7 +10,8 @@
/* ════════════════════════ INSPECTOR (Details) ════════════════════════ */
.insp { display: flex; flex-direction: column; height: 100%; min-height: 0; }
-.insp-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
+/* shared .phead, one row taller for the 26px search well */
+.insp-head { height: 38px; }
.insp-head .search { height: 26px; }
/* Outlined, not filled — the accent fill is reserved for Play (one primary
action per screen); +Add stays prominent through the accent stroke/text. */
@@ -89,10 +90,8 @@
.prop:hover .prop-reset.show, .prop.modified .prop-reset.show { opacity: .85; }
.prop-reset:hover { opacity: 1 !important; }
-.field { height: 22px; flex: 1; min-width: 0; display: flex; align-items: center; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
-.field:focus-within { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }
-.field input { width: 100%; min-width: 0; background: none; border: none; outline: none; padding: 0 7px; font-size: var(--fs-sm); color: var(--text); font-family: var(--mono); }
-.field select { width: 100%; background: none; border: none; outline: none; padding: 0 6px; font-size: var(--fs-sm); color: var(--text); appearance: none; cursor: pointer; }
+/* `.field` (the input well NumField and the dropdown trigger sit in) is the
+ shared primitive in controls.css. */
.vec { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; flex: 1; min-width: 0; }
.vfield { height: 22px; display: flex; align-items: center; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; min-width: 0; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.vfield:focus-within { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }
@@ -154,7 +153,6 @@
.snum { width: 54px; flex-shrink: 0; display: flex; }
/* ── themed dropdown / flags / asset picker (a Popover under the field) ── */
-.field.dropdown { padding: 0; overflow: hidden; }
.dd-trigger { width: 100%; height: 100%; display: flex; align-items: center; gap: 4px; padding: 0 4px 0 7px; background: none; border: none; color: var(--text); font-size: var(--fs-sm); cursor: pointer; min-width: 0; }
.dd-val { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-val.mixed { color: var(--text-mute); }
diff --git a/desktop/src/theme/outliner.css b/desktop/src/theme/outliner.css
index ee4fe7d83..031108a56 100644
--- a/desktop/src/theme/outliner.css
+++ b/desktop/src/theme/outliner.css
@@ -5,31 +5,8 @@
(.phead / .pbtn / .pbody) is shared with other docked panels and defined here.
========================================================================== */
-/* Panel header (search / actions row) — shared scaffolding */
-.phead {
- height: 32px;
- flex-shrink: 0;
- display: flex;
- align-items: center;
- gap: 6px;
- padding: 0 8px;
- border-bottom: 1px solid var(--border);
-}
-.pbtn {
- width: 24px;
- height: 24px;
- display: grid;
- place-items: center;
- color: var(--text-mute);
- border-radius: var(--r-sm);
- flex-shrink: 0;
- transition: color var(--t-fast), background var(--t-fast);
-}
-.pbtn:hover { color: var(--text); background: var(--srf-4); }
-.pbtn:active { background: var(--srf-5); }
-.pbtn:disabled { opacity: 0.4; cursor: default; }
-.pbtn.on { color: var(--acc); }
-.pbody { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
+/* Panel header scaffolding (.phead/.pbtn/.pbody) is the shared primitive in
+ controls.css; this file keeps only outliner-specific rows/columns. */
/* Column header strip */
.outliner-cols {
diff --git a/desktop/src/theme/sequencer.css b/desktop/src/theme/sequencer.css
index b9839d0f3..20c142f61 100644
--- a/desktop/src/theme/sequencer.css
+++ b/desktop/src/theme/sequencer.css
@@ -15,16 +15,11 @@
--seq-tracks-w: 224px;
}
-/* ── transport bar ── */
+/* ── transport bar — shared .phead, tight gap for the transport cluster ── */
.seq-bar {
- display: flex;
- align-items: center;
- gap: 3px;
height: 34px;
- flex: none;
- padding: 0 8px;
+ gap: 3px;
background: var(--elevated);
- border-bottom: 1px solid var(--border);
}
.seq-meta { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.seq-meta__icon { color: var(--acc-hi); }
@@ -175,12 +170,8 @@
display: flex; align-items: center; justify-content: space-between; gap: 10px;
padding: 5px 4px; font-size: 12px; color: var(--text-dim);
}
-.seq-settings__row input {
- width: 84px; background: var(--srf-2); border: 1px solid var(--border);
- color: var(--text); border-radius: var(--r-sm); padding: 3px 6px;
- font-family: var(--mono); font-size: var(--fs-xs);
-}
-.seq-settings__row input:focus { outline: none; border-color: var(--acc); }
+/* numeric cells are the shared NumField (.field well), capped to the popover column */
+.seq-settings__row .field { flex: 0 0 84px; }
.seq-settings__wrap { display: inline-flex; background: var(--srf-2); border-radius: var(--r-md); padding: 2px; }
.seq-settings__wrapbtn {
border: 0; background: transparent; color: var(--text-mute); cursor: pointer;