Add feature to allow editing a slider's value outside of its current range - #353
Open
jules-vanaret wants to merge 1 commit into
Open
Add feature to allow editing a slider's value outside of its current range#353jules-vanaret wants to merge 1 commit into
jules-vanaret wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #353 +/- ##
==========================================
- Coverage 84.90% 84.77% -0.13%
==========================================
Files 49 49
Lines 3928 3941 +13
==========================================
+ Hits 3335 3341 +6
- Misses 593 600 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
PR description
This is a small UX tweak for labeled range sliders.
The problem addressed is that if you edit a slider value label (the text box just above the slider knob) and type a value outside the current slider range, that value gets clamped at the slider bounds. This could be cumbersome for things like contrast-limit controls, where users might expect to be able to type a new endpoint directly instead of first adjusting the min/max edge labels (see napari/napari#9310 ).
Changes
SliderLabel.setValue()normally clamps values to the slider bounds when it refreshes labels. It now accepts aclamp_valuesparameter, which defaults toTrueto retain its existing bounds-clamping behavior for normal label updates.SliderLabel._editing_finished()passesclamp_values=Falsebefore emittingvalueEdited, allowing the owning range slider to receive the raw out-of-range value and decide whether to expand its bounds.I added an opt-in flag to the range slider itself to trigger the new behaviour:
expandRangeOnHandleEdit()setExpandRangeOnHandleEdit(bool)How to use it in practice
With that enabled, typing 110 into the upper handle label will expand the max to 110 and set the handle there instead of being stuck at the old bound.
Reproducer
The small example below illustrates simple- and double-sliders with and without the new range-expansion feature triggered. Try to modify e.g the value of one of the slider above 100 and observe the behavior.