added drag start and end events

This commit is contained in:
Emma 2023-02-08 01:20:37 -07:00
parent 0d6717896e
commit 880c0be4f1
2 changed files with 26 additions and 1 deletions

View File

@ -410,16 +410,25 @@ class Doodler {
}
this.draggables = this.draggables.filter((d)=>d.point !== point);
}
addDragEvents({ onDragEnd , onDragStart , point }) {
const d = this.draggables.find((d)=>d.point === point);
if (d) {
d.onDragEnd = onDragEnd;
d.onDragStart = onDragStart;
}
}
onClick(e) {
for (const d of this.draggables){
if (d.point.dist(new Vector(this.mouseX, this.mouseY)) <= d.radius) {
d.beingDragged = true;
d.onDragStart?.call(null);
} else d.beingDragged = false;
}
}
offClick(e) {
for (const d of this.draggables){
d.beingDragged = false;
d.onDragEnd?.call(null);
}
}
uiElements = new Map();

View File

@ -222,17 +222,31 @@ export class Doodler {
this.draggables = this.draggables.filter(d => d.point !== point);
}
addDragEvents({
onDragEnd,
onDragStart,
point
}: {point: Vector, onDragEnd: () => void, onDragStart: () => void}) {
const d = this.draggables.find(d =>d.point === point);
if (d) {
d.onDragEnd = onDragEnd;
d.onDragStart = onDragStart;
}
}
onClick(e: MouseEvent) {
for (const d of this.draggables) {
if (d.point.dist(new Vector(this.mouseX, this.mouseY)) <= d.radius) {
d.beingDragged = true;
d.onDragStart?.call(null);
} else d.beingDragged = false;
}
}
offClick(e:MouseEvent){
for (const d of this.draggables) {
d.beingDragged = false;
d.onDragEnd?.call(null);
}
}
@ -296,6 +310,8 @@ type Draggable = {
style?: IStyle & { shape: 'square' | 'circle' };
beingDragged?: boolean;
id: string;
onDragStart?: () => void;
onDragEnd?: () => void;
}
type uiDrawing = {