Skip to content

Commit

Permalink
allow brush size up to 1/2 diagonal image
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w committed Nov 22, 2024
1 parent 2eef345 commit 7cf80a7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,18 @@ onUiLoaded(async() => {
if (Math.abs(delta) < 1) {
delta = deltaY > 0 ? -1 : 1;
}
let newValue = currentRadius + delta;
input.value = Math.min(Math.max(newValue, 1), maxValue);
const newValue = currentRadius + delta;
// allow increasing the brush size beyond what's limited by gradio up to 1/2 diagonal of the image
if (newValue > maxValue) {
const canvasImg = gradioApp().querySelector(`${elemId} img`);
if (canvasImg) {
const maxDiameter = Math.sqrt(canvasImg.naturalWidth ** 2 + canvasImg.naturalHeight ** 2) / 2;
if (newValue < maxDiameter) {
input.setAttribute("max", newValue);
}
}
}
input.value = Math.max(newValue, 1);
input.dispatchEvent(new Event("change"));
}
}
Expand Down

0 comments on commit 7cf80a7

Please sign in to comment.