diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-09 04:03:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 04:03:30 +0000 |
commit | 7f9dbc45b103b54eabe9360fb878f987b5c61ffe (patch) | |
tree | 90b476001f30c6cb0aefc77b50116a9e8a990990 | |
parent | 08e538e2e60d87b413eef3e0e3e62f20ea2a54f5 (diff) | |
parent | e12a1be1ca23377a3d5774fe8d52664a9c2c0fb9 (diff) | |
download | stable-diffusion-webui-gfx803-7f9dbc45b103b54eabe9360fb878f987b5c61ffe.tar.gz stable-diffusion-webui-gfx803-7f9dbc45b103b54eabe9360fb878f987b5c61ffe.tar.bz2 stable-diffusion-webui-gfx803-7f9dbc45b103b54eabe9360fb878f987b5c61ffe.zip |
Merge pull request #12413 from daswer123/auto-expand
Zoom and pan: option to auto-expand a wide image
-rw-r--r-- | extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js | 29 | ||||
-rw-r--r-- | extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py | 1 |
2 files changed, 29 insertions, 1 deletions
diff --git a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js index 30199dcd..eb49a01d 100644 --- a/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js +++ b/extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js @@ -201,7 +201,8 @@ onUiLoaded(async() => { canvas_hotkey_overlap: "KeyO", canvas_disabled_functions: [], canvas_show_tooltip: true, - canvas_blur_prompt: false + canvas_auto_expand: true, + canvas_blur_prompt: false, }; const functionMap = { @@ -648,8 +649,34 @@ onUiLoaded(async() => { mouseY = e.offsetY; } + // Simulation of the function to put a long image into the screen. + // We define the size of the canvas, make a fullscreen to reveal the image, then reduce it to fit into the element. + // We hide the image and show it to the user when it is ready. + function autoExpand(e) { + const canvas = document.querySelector(`${elemId} canvas[key="interface"]`); + const isMainTab = activeElement === elementIDs.inpaint || activeElement === elementIDs.inpaintSketch || activeElement === elementIDs.sketch; + if (canvas && isMainTab) { + if (canvas && parseInt(targetElement.style.width) > 862 || parseInt(canvas.width) < 862) { + return; + } + if (canvas) { + targetElement.style.visibility = "hidden"; + setTimeout(() => { + fitToScreen(); + resetZoom(); + targetElement.style.visibility = "visible"; + }, 10); + } + } + } + targetElement.addEventListener("mousemove", getMousePosition); + // Apply auto expand if enabled + if (hotkeysConfig.canvas_auto_expand) { + targetElement.addEventListener("mousemove", autoExpand); + } + // Handle events only inside the targetElement let isKeyDownHandlerAttached = false; diff --git a/extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py b/extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py index 380176ce..2d8d2d1c 100644 --- a/extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py +++ b/extensions-builtin/canvas-zoom-and-pan/scripts/hotkey_config.py @@ -9,6 +9,7 @@ shared.options_templates.update(shared.options_section(('canvas_hotkey', "Canvas "canvas_hotkey_reset": shared.OptionInfo("R", "Reset zoom and canvas positon"), "canvas_hotkey_overlap": shared.OptionInfo("O", "Toggle overlap").info("Technical button, neededs for testing"), "canvas_show_tooltip": shared.OptionInfo(True, "Enable tooltip on the canvas"), + "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"), "canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"), "canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom","Adjust brush size", "Moving canvas","Fullscreen","Reset Zoom","Overlap"]}), })) |