diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/AnchorPresetIcon.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/AnchorPresetIcon.tsx new file mode 100644 index 000000000..80f950aad --- /dev/null +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/AnchorPresetIcon.tsx @@ -0,0 +1,142 @@ +export type AnchorMode = 'start' | 'center' | 'end' | 'stretch'; + +const PRESET_ICON_BOUNDARY = 3.5; +const PRESET_ICON_CENTER = 10; +const PRESET_ICON_EDGE = 16.5; + +function anchorCoordinate(mode: Exclude): number { + return mode === 'start' + ? PRESET_ICON_BOUNDARY + : mode === 'center' + ? PRESET_ICON_CENTER + : PRESET_ICON_EDGE; +} + +export function AnchorPresetIcon({ x, y }: { x: AnchorMode; y: AnchorMode }) { + const xStretch = x === 'stretch'; + const yStretch = y === 'stretch'; + const xPosition = xStretch ? PRESET_ICON_CENTER : anchorCoordinate(x); + const yPosition = yStretch ? PRESET_ICON_CENTER : anchorCoordinate(y); + + return ( + + ); +} diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/TransformEditor.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/TransformEditor.tsx index 2d99f5313..f541c42cd 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/TransformEditor.tsx +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/Inspector/Transform/TransformEditor.tsx @@ -5,7 +5,6 @@ import { Crosshair, Info, LockKeyhole, - Maximize2, Move, SlidersHorizontal, Unlock, @@ -13,6 +12,7 @@ import { import { useEffect, useMemo, useRef, useState } from 'react'; import type { Transform } from '../../../../../features/ui-editor/types/Transform'; +import { type AnchorMode, AnchorPresetIcon } from './AnchorPresetIcon'; export type TransformEditorParentSize = { width: number; @@ -27,7 +27,6 @@ export type TransformEditorProps = { }; type Axis = 0 | 1; -type AnchorMode = 'left' | 'center' | 'right' | 'stretch'; type AnchorPreset = { id: string; label: string; @@ -37,19 +36,19 @@ type AnchorPreset = { const AXIS_LABELS = ['X', 'Y'] as const; const AXIS_MODE_LABELS: Record = { - left: '左侧', + start: '左侧', center: '居中', - right: '右侧', + end: '右侧', stretch: '拉伸', }; const ROW_MODE_LABELS: Record = { - left: '顶部', + start: '顶部', center: '居中', - right: '底部', + end: '底部', stretch: '拉伸', }; -const COLUMN_MODES: AnchorMode[] = ['left', 'center', 'right', 'stretch']; -const ROW_MODES: AnchorMode[] = ['left', 'center', 'right', 'stretch']; +const COLUMN_MODES: AnchorMode[] = ['start', 'center', 'end', 'stretch']; +const ROW_MODES: AnchorMode[] = ['start', 'center', 'end', 'stretch']; const PRESETS: AnchorPreset[] = ROW_MODES.flatMap((y) => COLUMN_MODES.map((x) => ({ @@ -63,8 +62,8 @@ const PRESETS: AnchorPreset[] = ROW_MODES.flatMap((y) => const CUSTOM_PRESET: AnchorPreset = { id: 'custom', label: '自定义', - x: 'left', - y: 'left', + x: 'start', + y: 'start', }; const FIELD_HINTS = { @@ -91,7 +90,7 @@ function modeAnchors(mode: AnchorMode): [number, number] { if (mode === 'stretch') { return [0, 1]; } - const value = mode === 'left' ? 0 : mode === 'center' ? 0.5 : 1; + const value = mode === 'start' ? 0 : mode === 'center' ? 0.5 : 1; return [value, value]; } @@ -501,16 +500,7 @@ export function TransformEditor({ setPresetOpen(false); }} > - - - {column === 'stretch' || row === 'stretch' ? ( - + ); }),