fixup draggable

This commit is contained in:
Lentil Hoffman 2025-12-26 14:01:50 -06:00
parent acb86f23d2
commit bc490b4878
Signed by: lentil
GPG Key ID: 0F5B99F3F4D0C087
2 changed files with 4 additions and 4 deletions

View File

@ -14,7 +14,7 @@ export class Overlay {
infoBox.style.left = 0; infoBox.style.left = 0;
infoBox.width = 'fit-content'; infoBox.width = 'fit-content';
infoBox.style.zIndex = 1; infoBox.style.zIndex = 1;
infoBox.classList.add('draggable'); infoBox.classList.add(DRAGGABLE_ELEMENT_CLASSNAME);
} }
renderInfo() { renderInfo() {

View File

@ -43,7 +43,7 @@ export class Pointer {
while (target && !target.classList.contains(DRAGGABLE_ELEMENT_CLASSNAME)) { while (target && !target.classList.contains(DRAGGABLE_ELEMENT_CLASSNAME)) {
target = target.parentElement; target = target.parentElement;
} }
if (target?.classList.contains('draggable')) { if (target?.classList.contains(DRAGGABLE_ELEMENT_CLASSNAME)) {
// e.preventDefault(); // e.preventDefault();
this.draggingElement = target; this.draggingElement = target;
this.draggingElement.dragging = { this.draggingElement.dragging = {
@ -130,15 +130,15 @@ export class Pointer {
} }
// Handle cursor (mouse or touch) movement // Handle cursor (mouse or touch) movement
// TODO: If e.touches.length > 1, user may be engaging pinch to zoom
handlePointerMove({x, y}) { handlePointerMove({x, y}) {
this.updatePointer({x, y}); this.updatePointer({x, y});
// TODO: If e.touches.length > 1, user may be engaging pinch to zoom const {x: vx, y: vy} = this.getPointerVelocity();
// If the cursor moves while creating an object, or while an object is selected, // If the cursor moves while creating an object, or while an object is selected,
// update the position and velocity of the object // update the position and velocity of the object
const obj = this.sim.objects.getSelectedOrCreating(); const obj = this.sim.objects.getSelectedOrCreating();
if (obj !== undefined) { if (obj !== undefined) {
const {x: vx, y: vy} = this.getPointerVelocity();
obj.position.x = x; obj.position.x = x;
obj.position.y = y; obj.position.y = y;
obj.velocity.x = vx; obj.velocity.x = vx;