just so much groundwork

This commit is contained in:
2025-02-05 04:00:40 -07:00
parent b3772052f5
commit 952b5dd57f
22 changed files with 1003 additions and 2081 deletions

39
ui/button.ts Normal file
View File

@@ -0,0 +1,39 @@
import { Doodler, Vector } from "@bearmetal/doodler";
import { getContext, getContextItem } from "../lib/context.ts";
export function addButton(props: {
text: string;
onClick: () => void;
style?: {
color?: string;
fillColor?: string;
strokeColor?: string;
weight?: number;
noStroke?: boolean;
noFill?: boolean;
};
at: [Vector, Vector];
}) {
const doodler = getContextItem<Doodler>("doodler");
const { text, onClick, style } = props;
const { x, y } = props.at[1].copy().sub(props.at[0]);
const id = doodler.addUIElement(
"rectangle",
props.at[0],
x,
y,
style,
);
doodler.registerClickable(props.at[0], props.at[1], onClick);
return {
id,
text,
onClick,
style,
};
}
export function removeButton(id: string, onClick: () => void) {
getContextItem<Doodler>("doodler").removeUIElement(id);
getContextItem<Doodler>("doodler").unregisterClickable(onClick);
}