We have UI! kind of

This commit is contained in:
Dustin Swan 2026-02-01 23:26:30 -07:00
parent 52647a9ce1
commit 5b40e9d298
No known key found for this signature in database
GPG key ID: 30D46587E2100467
7 changed files with 221 additions and 40 deletions

View file

@ -1,30 +1,30 @@
import type { UIValue } from './types';
import { render } from './ui';
import { evaluate } from './interpreter'
import type { Env } from './env'
import { tokenize } from './lexer'
import { Parser } from './parser'
import cgCode from './counter.cg?raw';
import { runApp } from './runtime';
const canvas = document.createElement('canvas');
canvas.width = 800;
canvas.height = 600;
document.body.appendChild(canvas);
const ui: UIValue = {
kind: 'column',
gap: 10,
children: [
{ kind: 'text', content: "Hello CG World", x: 0, y: 20 },
{ kind: 'rect', w: 200, h: 50, color: 'blue' },
{ kind: 'text', content: "YESS", x: 0, y: 20 },
{ kind: 'row', gap: 13, children:
[
{ kind: 'text', content: "In a row", x: 0, y: 10 },
{ kind: 'clickable', event: "test", child: {
kind: 'padding', amount: 10, child: {
kind: 'rect', w: 80, h: 30, color: '#4a90e2'
}
}
}
]
}
]
};
const tokens = tokenize(cgCode);
const parser = new Parser(tokens);
const ast = parser.parse();
console.log(ast);
render(ui, canvas);
const env: Env = new Map();
const appRecord = evaluate(ast, env);
console.log(appRecord);
if (appRecord.kind !== 'record')
throw new Error('Expected record');
const init = appRecord.fields.init;
const update = appRecord.fields.update;
const view = appRecord.fields.view;
runApp({ init, update, view }, canvas);