allow brush size up to 1/2 diagonal image

This commit is contained in:
w-e-w 2024-11-22 11:00:26 +09:00
parent 2eef345743
commit 7cf80a70d9

View File

@ -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"));
}
}