Skip to content

Commit 2eef345

Browse files
committed
reduce complexity
remove the overly complex option of radius / area brush size change mode
1 parent 3a1497a commit 2eef345

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -474,25 +474,16 @@ onUiLoaded(async() => {
474474
if (input) {
475475
input.click();
476476
if (!withoutValue) {
477-
const maxValue =
478-
parseFloat(input.getAttribute("max")) || 100;
479-
if (opts.canvas_hotkey_brush_factor_mode === "Radius") {
480-
const changeAmount = maxValue * (percentage / 100);
481-
const newValue =
482-
parseFloat(input.value) +
483-
(deltaY > 0 ? -changeAmount : changeAmount);
484-
input.value = Math.min(Math.max(newValue, 0), maxValue);
485-
} else {
486-
const brush_factor = deltaY > 0 ? 1 - opts.canvas_hotkey_brush_factor : 1 + opts.canvas_hotkey_brush_factor;
487-
const currentRadius = parseFloat(input.value);
488-
let delta = Math.sqrt(currentRadius ** 2 * brush_factor) - currentRadius;
489-
// gradio seems to have a minimum brush size step of 1
490-
if (Math.abs(delta) < 1) {
491-
delta = delta > 0 ? 1 : -1;
492-
}
493-
const newValue = currentRadius + delta;
494-
input.value = Math.min(Math.max(newValue, 0), maxValue);
477+
const maxValue = parseFloat(input.getAttribute("max")) || 100;
478+
const brush_factor = deltaY > 0 ? 1 - opts.canvas_hotkey_brush_factor : 1 + opts.canvas_hotkey_brush_factor;
479+
const currentRadius = parseFloat(input.value);
480+
let delta = Math.sqrt(currentRadius ** 2 * brush_factor) - currentRadius;
481+
// minimum brush size step of 1
482+
if (Math.abs(delta) < 1) {
483+
delta = deltaY > 0 ? -1 : 1;
495484
}
485+
let newValue = currentRadius + delta;
486+
input.value = Math.min(Math.max(newValue, 1), maxValue);
496487
input.dispatchEvent(new Event("change"));
497488
}
498489
}

extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
"canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"),
1717
"canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"),
1818
"canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom", "Adjust brush size", "Hotkey enlarge brush", "Hotkey shrink brush", "Undo", "Clear", "Moving canvas", "Fullscreen", "Reset Zoom", "Overlap"]}),
19-
"canvas_hotkey_brush_factor_mode": shared.OptionInfo("Area", "Brush size adjustment mode", gr.Radio, {"choices": ["Area", "Radius"]}),
20-
"canvas_hotkey_brush_factor": shared.OptionInfo(0.1, "Brush factor", gr.Slider, {"minimum": 0, "maximum": 2, "step": 0.01})
19+
"canvas_hotkey_brush_factor": shared.OptionInfo(0.1, "Brush size change rate", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}).info('controls how much the brush size is changed when using hotkeys or scroll wheel'),
2120
}))

0 commit comments

Comments
 (0)