-
-
Notifications
You must be signed in to change notification settings - Fork 4k
SliderPrecision component #20032
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
SliderPrecision component #20032
Conversation
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.
In addition to my other nits, CoreSlider
needs breadcrumbs linking to this new component.
@@ -324,13 +359,16 @@ pub(crate) fn slider_on_drag( | |||
} else { | |||
range.start() + span * 0.5 | |||
}; | |||
let rounded_value = precision | |||
.map(|prec| prec.round(new_value)) |
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.
Need to clamp here, otherwise it can round the value to outside of the slider range
.map(|prec| prec.round(new_value)) | |
.map(|prec| range.clamp(prec.round(new_value))) |
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.
I'll do this slightly differently, because I don't want to clamp twice.
@@ -257,7 +288,9 @@ pub(crate) fn slider_on_pointer_down( | |||
value.0 + step.0 | |||
} | |||
} | |||
TrackClick::Snap => click_val, | |||
TrackClick::Snap => precision | |||
.map(|prec| prec.round(click_val)) |
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.
.map(|prec| prec.round(click_val)) | |
.map(|prec| range.clamp(prec.round(click_val))) |
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 is already clamped, see previous lines.
@viridia ping me when merge conflicts are resolved please :) |
Rebased! |
This PR adds a
SliderPrecision
component that lets you control the rounding when dragging a slider.Part of #19236