From 7cf80a70d9ff33eca787a57beaaf3c61eb6a40af Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:00:26 +0900 Subject: [PATCH] allow brush size up to 1/2 diagonal image --- .../canvas-zoom-and-pan/javascript/zoom.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index 714e29de639..85d8c2cbb08 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -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")); } }