avoid resizing past zero

This commit is contained in:
Orion Reed 2024-12-02 06:31:35 -05:00
parent da4d15f97c
commit f32699985d
1 changed files with 28 additions and 8 deletions

View File

@ -408,25 +408,45 @@ export class FolkShape extends HTMLElement {
if (part === null) return; if (part === null) return;
if (part.includes('resize')) { if (part.includes('resize')) {
console.log(part, event.movementX, event.movementY); let newWidth = this.width;
// This triggers a move and resize event :( let newHeight = this.height;
let newX = this.x;
let newY = this.y;
if (part.includes('-n')) { if (part.includes('-n')) {
this.y += event.movementY; const proposedHeight = this.height - event.movementY;
this.height -= event.movementY; if (proposedHeight > 0) {
newHeight = proposedHeight;
newY = this.y + event.movementY;
}
} }
if (part.endsWith('e')) { if (part.endsWith('e')) {
this.width += event.movementX; const proposedWidth = this.width + event.movementX;
if (proposedWidth > 0) {
newWidth = proposedWidth;
}
} }
if (part.includes('-s')) { if (part.includes('-s')) {
this.height += event.movementY; const proposedHeight = this.height + event.movementY;
if (proposedHeight > 0) {
newHeight = proposedHeight;
}
} }
if (part.endsWith('w')) { if (part.endsWith('w')) {
this.x += event.movementX; const proposedWidth = this.width - event.movementX;
this.width -= event.movementX; if (proposedWidth > 0) {
newWidth = proposedWidth;
newX = this.x + event.movementX;
}
} }
this.width = newWidth;
this.height = newHeight;
this.x = newX;
this.y = newY;
return; return;
} }