|
|
|
|
@ -77,6 +77,9 @@ export function runApp(app: App, canvas: HTMLCanvasElement, source: string) {
|
|
|
|
|
handleEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rerender();
|
|
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
|
if (error instanceof CGError) {
|
|
|
|
|
console.error(error.format());
|
|
|
|
|
@ -120,7 +123,7 @@ export function runApp(app: App, canvas: HTMLCanvasElement, source: string) {
|
|
|
|
|
child: viewUI,
|
|
|
|
|
event: {
|
|
|
|
|
kind: 'constructor',
|
|
|
|
|
name: 'Focus',
|
|
|
|
|
name: 'FocusAndClick',
|
|
|
|
|
args: [{ kind: 'string', value: fullKey }]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@ -201,9 +204,41 @@ export function runApp(app: App, canvas: HTMLCanvasElement, source: string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleEvent(event: Value) {
|
|
|
|
|
if (event.kind === 'constructor' && event.name === 'Focus') {
|
|
|
|
|
if (event.args.length > 0 && event.args[0].kind === 'string') {
|
|
|
|
|
setFocus(event.args[0].value);
|
|
|
|
|
if (event.kind === 'constructor' && event.name === 'FocusAndClick') {
|
|
|
|
|
if (event.args.length === 2 && event.args[0].kind === 'string') {
|
|
|
|
|
const componentKey = event.args[0].value;
|
|
|
|
|
const coords = event.args[1];
|
|
|
|
|
|
|
|
|
|
setFocus(componentKey);
|
|
|
|
|
|
|
|
|
|
handleComponentEvent(componentKey, {
|
|
|
|
|
kind: 'constructor',
|
|
|
|
|
name: 'Clicked',
|
|
|
|
|
args: [coords]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.kind === 'constructor' && event.name === 'Update') {
|
|
|
|
|
if (event.args.length === 2) {
|
|
|
|
|
const ref = event.args[0];
|
|
|
|
|
const transformFn = event.args[1];
|
|
|
|
|
|
|
|
|
|
if (ref.kind !== 'ref')
|
|
|
|
|
throw new Error('Update event expects a Ref')
|
|
|
|
|
|
|
|
|
|
if (transformFn.kind !== 'closure')
|
|
|
|
|
throw new Error('Update event expects a Ref')
|
|
|
|
|
|
|
|
|
|
const callEnv = new Map(transformFn.env);
|
|
|
|
|
callEnv.set(transformFn.params[0], ref.value);
|
|
|
|
|
const newValue = evaluate(transformFn.body, callEnv, source);
|
|
|
|
|
|
|
|
|
|
ref.value = newValue;
|
|
|
|
|
|
|
|
|
|
rerender();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -240,19 +275,22 @@ export function runApp(app: App, canvas: HTMLCanvasElement, source: string) {
|
|
|
|
|
if (hitResult) {
|
|
|
|
|
const { event, relativeX, relativeY } = hitResult;
|
|
|
|
|
|
|
|
|
|
if (event.kind === 'constructor' && event.name === 'Focus') {
|
|
|
|
|
if (event.kind === 'constructor' && (event.name === 'Focus' || event.name === 'Update')) {
|
|
|
|
|
handleEvent(event);
|
|
|
|
|
} else if (event.kind === 'constructor') {
|
|
|
|
|
} else if (event.kind === 'constructor' && event.name === 'FocusAndClick') {
|
|
|
|
|
const eventWithCoords: Value = {
|
|
|
|
|
kind: 'constructor',
|
|
|
|
|
name: event.name,
|
|
|
|
|
args: [{
|
|
|
|
|
kind: 'record',
|
|
|
|
|
fields: {
|
|
|
|
|
x: { kind: 'int', value: Math.floor(relativeX) },
|
|
|
|
|
y: { kind: 'int', value: Math.floor(relativeY) },
|
|
|
|
|
args: [
|
|
|
|
|
event.args[0],
|
|
|
|
|
{
|
|
|
|
|
kind: 'record',
|
|
|
|
|
fields: {
|
|
|
|
|
x: { kind: 'int', value: Math.floor(relativeX) },
|
|
|
|
|
y: { kind: 'int', value: Math.floor(relativeY) },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
handleEvent(eventWithCoords);
|
|
|
|
|
} else {
|
|
|
|
|
|