give the brush editor resize handle a maximum size

this is to prevent the size from going negative, which fucks a lot of things up (you end up not being able to drag it anymore 💀)
This commit is contained in:
liquidex 2024-09-03 22:52:12 +02:00
parent 740a62447e
commit 255511ac16
2 changed files with 13 additions and 7 deletions

View file

@ -55,7 +55,8 @@
data-direction="vertical"
data-target="panels-overlay"
data-target-property="--right-width"
data-init-size="384"></rkgk-resize-handle>
data-init-size="384"
data-min-size="128"></rkgk-resize-handle>
<rkgk-brush-editor></rkgk-brush-editor>
</div>
</div>

View file

@ -11,12 +11,10 @@ export class ResizeHandle extends HTMLElement {
this.target = document.getElementById(this.targetId);
this.targetProperty = this.getAttribute("data-target-property");
this.initSize = parseInt(this.getAttribute("data-init-size"));
this.minSize = parseInt(this.getAttribute("data-min-size"));
this.size = parseInt(localStorage.getItem(this.#localStorageKey));
if (this.size != this.size) {
this.size = this.initSize;
this.#setSize(parseInt(localStorage.getItem(this.#localStorageKey)));
this.#saveSize();
}
this.#updateTargetProperty();
this.visual = this.appendChild(document.createElement("div"));
@ -25,6 +23,13 @@ export class ResizeHandle extends HTMLElement {
this.#draggingBehaviour();
}
#setSize(newSize) {
if (newSize != newSize) {
this.size = this.initSize;
}
this.size = Math.max(this.minSize, newSize);
}
get #localStorageKey() {
return `rkgk.resizeHandle.size.${this.targetId}`;
}
@ -48,7 +53,7 @@ export class ResizeHandle extends HTMLElement {
let event = await listen([window, "mousemove"], [window, "mouseup"]);
if (event.type == "mousemove") {
if (this.direction == "vertical") {
this.size = startingSize + (mouseDown.clientX - event.clientX);
this.#setSize(startingSize + (mouseDown.clientX - event.clientX));
}
this.#updateTargetProperty();
} else if (event.type == "mouseup") {