-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Slider unable to produce range of odd values #3483
Labels
bug
Something is broken
Comments
The solution is probably to take the start of the range into account when rounding. if let Some(step) = self.step {
let start = self.range.start();
value = start + ((value - start) / step).round() * step;
} |
If I'm understanding what's going on in let range = 3.0..=31.0;
let start = *range.start();
ui.add(egui::Slider::from_get_set(
range,
|v: Option<f64>| -> f64 {
if let Some(v) = v {
self.slider_value = start + ((v - start) / 2_f64).round() * 2_f64;
}
return self.slider_value;
},
)); Using @YgorSouza suggestion, I get the desired behavior. |
Yeah, I agree that the step should start at the start value, and @YgorSouza's solution seems sounds - please make a PR 🙏 |
YgorSouza
added a commit
to YgorSouza/egui
that referenced
this issue
Oct 19, 2023
emilk
pushed a commit
that referenced
this issue
Nov 10, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When defining the
egui::Slider
bounds with a range having odd bounds (e.g.3..=31
) and step size of2_f64
, instead of having selectable values {3, 5, 7, ..., 29, 31}, values {4, 6, 8, ..., 30, 31} are provided. This is not remedied with.clamp_to_range(true)
. Similarly, providing a range3..=501
and a step size of2_f64
produces values {4, 10, 20, 30, ..., 490, 500, 501}. NOTE this scenario is also not remedied by using ranges starting at 1.0, either.To Reproduce
Expected Behavior
Actual Behavior
Screenshots
Hypothesis
I believe this may be the cause of the issue (slider.rs, lines 501-514):
Desktop
eframe = { git = "https://github.com/emilk/egui", branch = "master", features = ["persistence"] }
The text was updated successfully, but these errors were encountered: