M0: WIT package, MoonBit components, JS host, docs, CI (#1)
CI / test (push) Successful in 19s
CI / test (push) Successful in 19s
This commit was merged in pull request #1.
This commit is contained in:
1 parent
e5548fc067
commit
880ecd4102
141 files changed
+9681
-1
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// Render-list helpers. A draw-op is a jco-lifted WIT variant: {tag, val}.
|
||||
|
||||
/** Translate a draw-op list by (dx, dy), returning new ops. */
|
||||
export function translate(ops, dx, dy) {
|
||||
return ops.map((op) => {
|
||||
const v = op.val;
|
||||
switch (op.tag) {
|
||||
case 'fill-rect':
|
||||
case 'stroke-rect':
|
||||
return { tag: op.tag, val: { ...v, rect: { ...v.rect, x: v.rect.x + dx, y: v.rect.y + dy } } };
|
||||
case 'line':
|
||||
return { tag: op.tag, val: { ...v, start: { x: v.start.x + dx, y: v.start.y + dy }, end: { x: v.end.x + dx, y: v.end.y + dy } } };
|
||||
case 'circle':
|
||||
return { tag: op.tag, val: { ...v, center: { x: v.center.x + dx, y: v.center.y + dy } } };
|
||||
case 'text':
|
||||
return { tag: op.tag, val: { ...v, origin: { x: v.origin.x + dx, y: v.origin.y + dy } } };
|
||||
case 'push-clip':
|
||||
return { tag: op.tag, val: { ...v, x: v.x + dx, y: v.y + dy } };
|
||||
case 'pop-clip':
|
||||
return op;
|
||||
default:
|
||||
throw new Error(`unknown draw-op tag: ${op.tag}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Place a component's local-space ops at `rect`, clipped to it. */
|
||||
export function place(ops, rect) {
|
||||
return [
|
||||
{ tag: 'push-clip', val: { ...rect } },
|
||||
...translate(ops, rect.x, rect.y),
|
||||
{ tag: 'pop-clip', val: undefined },
|
||||
];
|
||||
}
|
||||
|
||||
export const colorCss = (c) => `rgba(${c.r},${c.g},${c.b},${(c.a / 255).toFixed(3)})`;
|
||||
Reference in new issue
Block a user