Cleaning up UI primitives. fixing parser bugs. still struggling to make a command palette lol

This commit is contained in:
Dustin Swan 2026-02-07 15:23:25 -07:00
parent 2d687b5d38
commit da97f53729
No known key found for this signature in database
GPG key ID: 30D46587E2100467
10 changed files with 66 additions and 23 deletions

View file

@ -27,7 +27,7 @@ export function render(ui: UIValue, canvas: HTMLCanvasElement) {
function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: number) {
switch (ui.kind) {
case 'rect': {
ctx.fillStyle = ui.color;
ctx.fillStyle = ui.color || 'transparent';
if (ui.radius && ui.radius > 0) {
const r = Math.min(ui.radius, ui.w / 2, ui.h / 2);
@ -43,8 +43,21 @@ function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: numb
ctx.arcTo(x, y, x + r, y, r);
ctx.closePath();
ctx.fill();
if (ui.strokeColor && ui.strokeWidth) {
ctx.strokeStyle = ui.strokeColor;
ctx.lineWidth = ui.strokeWidth;
ctx.stroke();
}
} else {
ctx.fillRect(x, y, ui.w, ui.h);
if (ui.strokeColor && ui.strokeWidth) {
ctx.strokeStyle = ui.strokeColor;
ctx.lineWidth = ui.strokeWidth;
ctx.strokeRect(x, y, ui.w, ui.h);;
}
}
break;
@ -53,7 +66,7 @@ function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: numb
case 'text':
ctx.fillStyle = 'black';
ctx.font = '16px "SF Mono", "Monaco", "Menlo", "Consolas", "Courier New", monospace';
ctx.fillText(ui.content, x + ui.x, y + ui.y);
ctx.fillText(ui.content, x, y);
break;
case 'row': {