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): add Text / Image / Container UI primitives to the palette

yhh3a4cede17468
diff --git a/desktop/src/engine/entitySources.ts b/desktop/src/engine/entitySources.ts
index cd217bb5f..e81640b70 100644
--- a/desktop/src/engine/entitySources.ts
+++ b/desktop/src/engine/entitySources.ts
@@ -11,7 +11,7 @@
* UI. (REARCH_ENTITY_CREATION E2.)
*/
import type { LucideIcon } from 'lucide-react';
-import { CircleDot, LayoutPanelTop, ToggleLeft, SlidersHorizontal, List, ChevronDown, SquareMousePointer, RectangleHorizontal, Box } from 'lucide-react';
+import { CircleDot, LayoutPanelTop, ToggleLeft, SlidersHorizontal, List, ChevronDown, SquareMousePointer, RectangleHorizontal, Box, Type, Image as ImageIcon, SquareDashed } from 'lucide-react';
import { BUILTIN_UI_PREFABS, BUILTIN_UI_WIDGET_NAMES, PREFAB_FORMAT_VERSION, getUserComponents, type PrefabData } from 'esengine';
import type { EntityId } from '@/types';
import { componentByName, componentDefaults, prettyLabel, componentCategory } from './schema';
@@ -166,6 +166,21 @@ const UI_WIDGET_ICON: Record<string, LucideIcon> = {
ListView: List,
};
+// UI primitives — the raw building blocks the widget prefabs are composed from: a
+// UINode (layout) plus, per role, a Text or UIVisual. Placed under the Canvas like
+// the widgets. Without these the palette jumped from Canvas straight to composite
+// widgets, with no way to drop a plain label, image, or layout container. Each maps
+// to one UI render component: Text→Text, Image→UIVisual, Container→bare UINode.
+const uiPx = (n: number) => ({ value: n, unit: 0 });
+const UI_PRIMITIVE_SPECS: { id: string; label: string; icon: LucideIcon; comps: CompSpec[] }[] = [
+ { id: 'ui-text', label: 'Text', icon: Type,
+ comps: ['Transform', ['UINode', { width: uiPx(160), height: uiPx(40) }], ['Text', { content: 'Text' }]] },
+ { id: 'ui-image', label: 'Image', icon: ImageIcon,
+ comps: ['Transform', ['UINode', { width: uiPx(100), height: uiPx(100) }], 'UIVisual'] },
+ { id: 'ui-container', label: 'Container', icon: SquareDashed,
+ comps: ['Transform', ['UINode', { width: uiPx(200), height: uiPx(120) }]] },
+];
+
/**
* The entity-anchor components — each seeds a plain entity of that type. THE authority
* for "which components can start an entity": add an anchor here and it appears in the
@@ -215,6 +230,14 @@ export const ENTITY_SOURCES: EntitySource[] = [
return preset('Canvas', ['Transform', ['Canvas', { designResolution: { x: d.width, y: d.height } }], 'UINode']);
},
},
+ ...UI_PRIMITIVE_SPECS.map((s): EntitySource => ({
+ id: s.id,
+ label: s.label,
+ category: 'UI',
+ icon: s.icon,
+ build: () => preset(s.label, s.comps),
+ placement: 'under-canvas',
+ })),
...BUILTIN_UI_WIDGET_NAMES.map((name): EntitySource => ({
id: `ui-${name.toLowerCase()}`,
label: name,
diff --git a/desktop/tests/create-catalog.test.ts b/desktop/tests/create-catalog.test.ts
index 9c045ecd1..01a0d6c04 100644
--- a/desktop/tests/create-catalog.test.ts
+++ b/desktop/tests/create-catalog.test.ts
@@ -42,6 +42,19 @@ describe('Create catalog (searchable source registry)', () => {
expect(ui).toEqual(expect.arrayContaining(['Canvas', 'Button', 'Toggle', 'Slider']));
});
+ it('UI primitives (Text / Image / Container) sit under the Canvas', async () => {
+ const ui = ENTITY_SOURCES.filter((s) => s.category === 'UI').map((s) => s.label);
+ expect(ui).toEqual(expect.arrayContaining(['Text', 'Image', 'Container']));
+
+ const text = ENTITY_SOURCES.find((s) => s.id === 'ui-text')!;
+ expect(text.placement).toBe('under-canvas');
+ const built = (await text.build({ parent: null })).entities[0];
+ expect(built.components.map((c) => c.type)).toEqual(['Transform', 'UINode', 'Text']);
+ // Seeded so a freshly-dropped label reads, not an empty invisible node.
+ expect((built.components.find((c) => c.type === 'Text')!.data as { content: string }).content).toBe('Text');
+ expect((built.components.find((c) => c.type === 'UINode')!.data as { width: { value: number } }).width.value).toBe(160);
+ });
+
it('sourceById round-trips a dragged palette id back to its source', () => {
for (const s of ENTITY_SOURCES.filter((x) => x.category === 'UI')) {
expect(sourceById(s.id)).toBe(s);