|
|
|
@ -39,10 +39,29 @@ export function render(ui: UIValue, canvas: HTMLCanvasElement) {
|
|
|
|
|
|
|
|
|
|
|
|
function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: number) {
|
|
|
|
function renderUI(ui: UIValue, ctx: CanvasRenderingContext2D, x: number, y: number) {
|
|
|
|
switch (ui.kind) {
|
|
|
|
switch (ui.kind) {
|
|
|
|
case 'rect':
|
|
|
|
case 'rect': {
|
|
|
|
ctx.fillStyle = ui.color;
|
|
|
|
ctx.fillStyle = ui.color;
|
|
|
|
ctx.fillRect(x, y, ui.w, ui.h);
|
|
|
|
|
|
|
|
|
|
|
|
if (ui.radius && ui.radius > 0) {
|
|
|
|
|
|
|
|
const r = Math.min(ui.radius, ui.w / 2, ui.h / 2);
|
|
|
|
|
|
|
|
ctx.beginPath();
|
|
|
|
|
|
|
|
ctx.moveTo(x + r, y);
|
|
|
|
|
|
|
|
ctx.lineTo(x + ui.w - r, y);
|
|
|
|
|
|
|
|
ctx.arcTo(x + ui.w, y, x + ui.w, y + r, r);
|
|
|
|
|
|
|
|
ctx.lineTo(x + ui.w, y + ui.h - r);
|
|
|
|
|
|
|
|
ctx.arcTo(x + ui.w, y + ui.h, x + ui.w - r, y + ui.h, r);
|
|
|
|
|
|
|
|
ctx.lineTo(x + r, y + ui.h);
|
|
|
|
|
|
|
|
ctx.arcTo(x, y + ui.h, x, y + ui.h - r, r);
|
|
|
|
|
|
|
|
ctx.lineTo(x, y + r);
|
|
|
|
|
|
|
|
ctx.arcTo(x, y, x + r, y, r);
|
|
|
|
|
|
|
|
ctx.closePath();
|
|
|
|
|
|
|
|
ctx.fill();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ctx.fillRect(x, y, ui.w, ui.h);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'text':
|
|
|
|
case 'text':
|
|
|
|
ctx.fillStyle = 'black';
|
|
|
|
ctx.fillStyle = 'black';
|
|
|
|
|