Split GraphCanvas (1076 -> 831 lines) into EdgeLayer and graphMenus; the port and marker menus were the same list and are now one function. Value specs of the inspector and the list tab share valueSpecs.ts, and the remaining copies (compound commands, type glyphs, typed asset lookup, name rule, play/editor world setup, marquee) are merged. Four copies had already drifted apart; merging them fixes: - "Disconnect N links" in the port menu is one undo step, not N - "+ Add collider" is hidden on a placed container instance, as in the hierarchy menu, instead of always failing - a bool property coerced from the text "false" becomes false - a port command on an unknown node type reports instead of crashing Comment-only edits leave the bundle byte-identical. README corrected in 35 places (step limit, jump-run clock, suite duration, 409 body, ...). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
128 lines
4.3 KiB
TypeScript
128 lines
4.3 KiB
TypeScript
import type { Application } from 'pixi.js';
|
||
import {
|
||
Button,
|
||
Checkbox,
|
||
ColorField,
|
||
Dialog,
|
||
HStack,
|
||
Label,
|
||
ListView,
|
||
Menu,
|
||
NumberField,
|
||
Panel,
|
||
ScrollContainer,
|
||
TextField,
|
||
Theme,
|
||
type VStack,
|
||
toHex,
|
||
} from './ui';
|
||
|
||
/**
|
||
* Developer page (`?playground`) that shows every widget of the toolkit for manual
|
||
* testing: focus cycling, typing, scrubbing, color picking, scrolling, popups.
|
||
*/
|
||
export function mountPlayground(app: Application, root: VStack): void {
|
||
const status = new Label('Interact with the widgets – events are logged here.', {
|
||
style: 'muted',
|
||
padding: Theme.padding,
|
||
});
|
||
const log = (message: string) => status.setText(message);
|
||
|
||
const row = new HStack({ gap: Theme.padding, padding: Theme.padding });
|
||
|
||
const inputs = new Panel({ title: 'Inputs' });
|
||
inputs.content.add(new Label('Text field'));
|
||
inputs.content.add(
|
||
new TextField('Crate', {
|
||
placeholder: 'Name',
|
||
onInput: (v) => log(`text input: ${v}`),
|
||
onChange: (v) => log(`text change: ${v}`),
|
||
}),
|
||
);
|
||
inputs.content.add(new Label('Number field (drag to scrub)'));
|
||
inputs.content.add(
|
||
new NumberField(100, {
|
||
min: 1,
|
||
step: 1,
|
||
onInput: (v) => log(`number input: ${v}`),
|
||
onChange: (v) => log(`number change: ${v}`),
|
||
}),
|
||
);
|
||
inputs.content.add(
|
||
new NumberField(1, { min: 0.1, max: 10, step: 0.1, onChange: (v) => log(`zoom change: ${v}`) }),
|
||
);
|
||
inputs.content.add(new Label('Color field'));
|
||
inputs.content.add(
|
||
new ColorField(0xe0553f, {
|
||
onInput: (c) => log(`color input: ${toHex(c)}`),
|
||
onChange: (c) => log(`color change: ${toHex(c)}`),
|
||
}),
|
||
);
|
||
const checkRow = new HStack({ gap: Theme.gap, align: 'center' });
|
||
const checkbox = new Checkbox(true);
|
||
checkbox.onChange = (v) => log(`checkbox: ${v}`);
|
||
checkRow.add(checkbox);
|
||
checkRow.add(new Label('Checkbox'), 1);
|
||
inputs.content.add(checkRow);
|
||
row.add(inputs, 1);
|
||
|
||
const actions = new Panel({ title: 'Buttons & popups' });
|
||
actions.content.add(new Button('Default', { onClick: () => log('default clicked') }));
|
||
actions.content.add(new Button('Primary', { variant: 'primary', onClick: () => log('primary clicked') }));
|
||
const toggle = new Button('Toggle me');
|
||
toggle.onClick = () => {
|
||
toggle.setToggled(!toggle.toggled);
|
||
log(`toggled: ${toggle.toggled}`);
|
||
};
|
||
actions.content.add(toggle);
|
||
actions.content.add(new Button('Ghost', { variant: 'ghost', onClick: () => log('ghost clicked') }));
|
||
const disabled = new Button('Disabled');
|
||
disabled.setEnabled(false);
|
||
actions.content.add(disabled);
|
||
const menuButton = new Button('Open menu…');
|
||
menuButton.onClick = () => {
|
||
new Menu([
|
||
{ label: 'Scene', onSelect: () => log('menu: scene') },
|
||
{ label: 'Camera', onSelect: () => log('menu: camera') },
|
||
{ label: 'Sprite', onSelect: () => log('menu: sprite') },
|
||
{ label: 'Delete', danger: true, onSelect: () => log('menu: delete') },
|
||
]).openBelow(menuButton);
|
||
};
|
||
actions.content.add(menuButton);
|
||
actions.content.add(
|
||
new Button('Open dialog…', {
|
||
onClick: () =>
|
||
new Dialog('Delete asset?', 'Every placed instance is removed as well.', [
|
||
{ label: 'Cancel' },
|
||
{ label: 'Delete', danger: true, onClick: () => log('dialog: deleted') },
|
||
]).openCentered(),
|
||
}),
|
||
);
|
||
row.add(actions, 1);
|
||
|
||
const listPanel = new Panel({ title: 'List (scroll)', padding: 0 });
|
||
const scroll = new ScrollContainer();
|
||
const list = new ListView();
|
||
list.setItems(
|
||
Array.from({ length: 40 }, (_, i) => ({
|
||
id: `item-${i}`,
|
||
label: `Item ${i + 1}${i % 7 === 0 ? ' with a rather long name that must truncate' : ''}`,
|
||
hint: i % 3 === 0 ? 'sprite' : i % 3 === 1 ? 'camera' : 'scene',
|
||
swatch: i % 3 === 0 ? (0x3fa0e0 + i * 0x040201) & 0xffffff : undefined,
|
||
depth: i % 5 === 4 ? 1 : 0,
|
||
})),
|
||
);
|
||
list.onSelect = (id) => log(`list select: ${id}`);
|
||
list.onActivate = (id) => log(`list activate: ${id}`);
|
||
list.onContextMenu = (id, x, y) =>
|
||
new Menu([{ label: `Context for ${id}`, onSelect: () => log(`context: ${id}`) }]).open(x, y);
|
||
scroll.setContent(list);
|
||
listPanel.content.add(scroll, 1);
|
||
row.add(listPanel, 1);
|
||
|
||
root.add(new Label('Game Maker – UI playground', { style: 'bodyBold', padding: Theme.padding }));
|
||
root.add(row, 1);
|
||
root.add(status);
|
||
root.resize(app.screen.width, app.screen.height);
|
||
}
|