Skip to content

Instantly share code, notes, and snippets.

@tomhicks
Forked from rayrayzayzay/Example 2.ts
Last active May 24, 2023 17:59
Show Gist options
  • Save tomhicks/64d6d76bddffdd5743a021e9c992de76 to your computer and use it in GitHub Desktop.
Save tomhicks/64d6d76bddffdd5743a021e9c992de76 to your computer and use it in GitHub Desktop.
let mode: "idle" | "dragging" = "idle"
const dragHandler: InteractionHandler = {
onDragStart(gesture, app) {
if (intersection(gesture.elementsUnderCursor, app.selectedElements).size) {
mode = "dragging";
}
},
onPointerMove(gesture) {
// ignore pointer-moves when we haven't started dragging
if (mode !== "dragging") return;
const delta = sub(gesture.current.point, gesture.start.point);
transformSelectedElements(delta)
// prevents other pointermove handlers acting (not important for this case)
gesture.wasHandled();
},
onDragEnd() {
mode = "idle";
},
};
const selectionHandler: InteractionHandler = {
onClick(gesture) {
addElementToSelectionSet(gesture.topElement);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment