Created
May 24, 2023 01:05
-
-
Save rayrayzayzay/738dbcc21765c789f3da8ff1cd815377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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