-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to update when releasing mouse button from slide #2228
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f2b3eff
Add option to update when releasing mouse button from slide
5f59442
Merge branch 'master' into master
lwhitefox 1b6eaaf
Merge branch 'master' into master
lwhitefox 05319ea
Add value_dragstop output observable to allow updates on mouse release
a27fa4c
Merge branch 'master' into master
SimonDanisch 8c4c2c8
Merge branch 'master' into master
SimonDanisch 4c238b9
Merge branch 'MakieOrg:master' into master
lwhitefox 699dcae
Remove unused code; clarified documentation
db25f87
Merge branch 'master' into master
SimonDanisch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,9 @@ function initialize_block!(sl::Slider) | |
|
||
on(selected_index) do i | ||
sl.value[] = sliderrange[][i] | ||
if !dragging[] | ||
sl.value_dragstop[] = sliderrange[][i] | ||
end | ||
end | ||
|
||
# initialize slider value with closest from range | ||
|
@@ -93,19 +96,18 @@ function initialize_block!(sl::Slider) | |
|
||
onmouseleftdrag(mouseevents) do event | ||
dragging[] = true | ||
dif = event.px - event.prev_px | ||
fraction = clamp(if sl.horizontal[] | ||
(event.px[1] - endpoints[][1][1]) / (endpoints[][2][1] - endpoints[][1][1]) | ||
else | ||
(event.px[2] - endpoints[][1][2]) / (endpoints[][2][2] - endpoints[][1][2]) | ||
end, 0, 1) | ||
# dif is never used? | ||
# dif = event.px - event.prev_px | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these comments can be removed then |
||
|
||
fraction = current_sliderfraction(sl, event, endpoints, sliderrange) | ||
displayed_sliderfraction[] = fraction | ||
|
||
newindex = closest_fractionindex(sliderrange[], fraction) | ||
if sl.snap[] | ||
fraction = (newindex - 1) / (length(sliderrange[]) - 1) | ||
end | ||
displayed_sliderfraction[] = fraction | ||
|
||
newindex = closest_fractionindex(sliderrange[], fraction) | ||
if selected_index[] != newindex | ||
selected_index[] = newindex | ||
end | ||
|
@@ -115,8 +117,11 @@ function initialize_block!(sl::Slider) | |
|
||
onmouseleftdragstop(mouseevents) do event | ||
dragging[] = false | ||
# selected_index should be set correctly in onmouseleftdrag | ||
sl.value_dragstop = sliderrange[][selected_index[]] | ||
# adjust slider to closest legal value | ||
sliderfraction[] = sliderfraction[] | ||
# This line is not necessary? | ||
# sliderfraction[] = sliderfraction[] | ||
linecolors[] = [sl.color_active_dimmed[], sl.color_inactive[]] | ||
return Consume(true) | ||
end | ||
|
@@ -126,6 +131,7 @@ function initialize_block!(sl::Slider) | |
dim = sl.horizontal[] ? 1 : 2 | ||
frac = (pos[dim] - endpoints[][1][dim]) / (endpoints[][2][dim] - endpoints[][1][dim]) | ||
selected_index[] = closest_fractionindex(sliderrange[], frac) | ||
sl.value_dragstop = sliderrange[][selected_index[]] | ||
# linecolors[] = [color_active[], color_inactive[]] | ||
return Consume(true) | ||
end | ||
|
@@ -151,6 +157,23 @@ function initialize_block!(sl::Slider) | |
sl | ||
end | ||
|
||
|
||
function current_sliderfraction(sl, event, endpoints, sliderrange) | ||
fraction = clamp(if sl.horizontal[] | ||
(event.px[1] - endpoints[][1][1]) / (endpoints[][2][1] - endpoints[][1][1]) | ||
else | ||
(event.px[2] - endpoints[][1][2]) / (endpoints[][2][2] - endpoints[][1][2]) | ||
end, 0, 1 | ||
) | ||
|
||
newindex = closest_fractionindex(sliderrange[], fraction) | ||
if sl.snap[] | ||
fraction = (newindex - 1) / (length(sliderrange[]) - 1) | ||
end | ||
|
||
return fraction | ||
end | ||
|
||
function valueindex(sliderrange, value) | ||
for (i, val) in enumerate(sliderrange) | ||
if val == value | ||
|
@@ -197,4 +220,5 @@ function set_close_to!(slider::Slider, value) | |
closest = closest_index(slider.range[], value) | ||
slider.selected_index = closest | ||
slider.range[][closest] | ||
slider.value_dragstop = slider.range[][closest] | ||
end |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_cloe_to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this section should go before the example I think, with an appropriate subheading