Skip to content

Commit 7cf80a7

Browse files
committed
allow brush size up to 1/2 diagonal image
1 parent 2eef345 commit 7cf80a7

File tree

1 file changed

+12
-2
lines changed
  • extensions-builtin/canvas-zoom-and-pan/javascript

1 file changed

+12
-2
lines changed

extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,18 @@ onUiLoaded(async() => {
482482
if (Math.abs(delta) < 1) {
483483
delta = deltaY > 0 ? -1 : 1;
484484
}
485-
let newValue = currentRadius + delta;
486-
input.value = Math.min(Math.max(newValue, 1), maxValue);
485+
const newValue = currentRadius + delta;
486+
// allow increasing the brush size beyond what's limited by gradio up to 1/2 diagonal of the image
487+
if (newValue > maxValue) {
488+
const canvasImg = gradioApp().querySelector(`${elemId} img`);
489+
if (canvasImg) {
490+
const maxDiameter = Math.sqrt(canvasImg.naturalWidth ** 2 + canvasImg.naturalHeight ** 2) / 2;
491+
if (newValue < maxDiameter) {
492+
input.setAttribute("max", newValue);
493+
}
494+
}
495+
}
496+
input.value = Math.max(newValue, 1);
487497
input.dispatchEvent(new Event("change"));
488498
}
489499
}

0 commit comments

Comments
 (0)