On Drag event

This commit is contained in:
Emma
2023-02-12 19:57:12 -07:00
parent 3d366a1a6c
commit c7ff737690
3 changed files with 42 additions and 35 deletions

View File

@@ -75,6 +75,7 @@ export class Doodler {
for (const d of this.draggables.filter(d => d.beingDragged)) {
d.point.add(e.movementX, e.movementY)
d.onDrag && d.onDrag({x: e.movementX, y: e.movementY});
}
})
this.startDrawLoop();
@@ -251,12 +252,14 @@ export class Doodler {
addDragEvents({
onDragEnd,
onDragStart,
onDrag,
point
}: { point: Vector, onDragEnd?: () => void, onDragStart?: () => void }) {
}: { point: Vector, onDragEnd?: () => void, onDragStart?: () => void, onDrag?: () => void }) {
const d = this.draggables.find(d => d.point === point);
if (d) {
d.onDragEnd = onDragEnd;
d.onDragStart = onDragStart;
d.onDrag = onDrag;
}
}
@@ -345,6 +348,7 @@ type Draggable = {
id: string;
onDragStart?: () => void;
onDragEnd?: () => void;
onDrag?: (dragDistance?: {x: number, y: number}) => void;
}
type Clickable = {