Repository navigation
Conversation
Adds a chain-link ToolButton next to the existing width/height
switch button in txt2img, img2img (Resize to), and Extras (Scale to).
When enabled, editing either the width or height slider/number field
(by typing or by dragging) automatically recalculates the other field
to preserve the aspect ratio captured at the moment the link was
turned on, rounded to the nearest valid step and clamped to that
field's own min/max.
- modules/ui.py: new link_dimensions_symbol and res_link_btn
ToolButton for txt2img and img2img, wired to toggleResLink().
- scripts/postprocessing_upscale.py: same button for the Extras
"Scale to" tab, wired to the generic toggleResLinkFor() so it can
use its own 64-8192 range instead of the 64-2048 range used by
txt2img/img2img.
- javascript/ui.js: toggleResLinkFor()/setupResLinkFor() implement
the linking logic, listening on both the number input and the
range input Gradio renders for each Slider (so it reacts to typing
and to dragging). toggleResLink()/setupResLink() are thin
convenience wrappers for the common "{tabname}_width"/"_height"
elem_id convention used by txt2img/img2img.
- style.css: .res-link-enabled gives the button a solid, opaque
background (var(--primary-600)) while the link is active, matching
the button color used elsewhere for primary actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a small chain-link ToolButton (🔗) next to the existing switch-width/height button (⇅) in three places:
When toggled on, it captures the current width/height ratio, and from then on editing either field — by typing in the number box or by dragging the slider — automatically recalculates the other field to keep that ratio, rounded to the field's step and clamped to its min/max. Toggling it off lets both fields move independently again, as today.
This is a small quality-of-life addition for anyone resizing/upscaling to a specific target resolution who wants to keep the source aspect ratio without doing the math by hand or re-checking it after every edit.
Screenshots
Off (default):
Width and Height sliders behave exactly as before.
On:
The link button gets a solid highlighted background (reusing the theme's
--primary-600, the same color used elsewhere for primary actions) so its state is clear at a glance. Dragging Width from 432 to 1024 (with Height starting at 768) automatically moves Height to 1816, preserving the original ~0.748 ratio.Implementation notes
javascript/ui.js:toggleResLinkFor(linkBtnId, widthElemId, heightElemId)andsetupResLinkFor(linkBtnId, widthElemId, heightElemId, minVal, maxVal, step)hold the actual linking logic. They listen on bothinput[type=number]andinput[type=range]for each field, since Gradio'sSliderrenders both and either one can be the source of a user edit.toggleResLink(tabname)/setupResLink(tabname)are thin convenience wrappers for the common"{tabname}_width"/"{tabname}_height"elem_id convention already used by txt2img/img2img, so existing call sites stay simple.state.syncing) prevents the programmatic update of the "other" field from re-triggering the handler.setupResLinkFor(...)directly with its own range rather than using the tabname-convention wrapper.modules/ui.py/scripts/postprocessing_upscale.py: newToolButtonper location, wired withfn=None, _js="...", following the exact same pattern already used by the neighboring switch-width/height button.style.css:.res-link-enabledgives the button an opaque background while active instead of a subtle transparency overlay, for better at-a-glance visibility.Test plan