Browse Source

[slider] round so what you see is what you get

pull/9/head
Emil Ernerfeldt 4 years ago
parent
commit
2162ffff42
  1. 7
      egui/src/math.rs
  2. 4
      egui/src/widgets/slider.rs

7
egui/src/math.rs

@ -591,3 +591,10 @@ pub fn ease_in_ease_out(t: f32) -> f32 {
}
pub const TAU: f32 = 2.0 * std::f32::consts::PI;
pub fn round_to_precision(value: f32, precision: usize) -> f32 {
// This is a stupid way of doing this, but stupid works.
format!("{:.*}", precision, value)
.parse()
.unwrap_or_else(|_| value)
}

4
egui/src/widgets/slider.rs

@ -91,9 +91,7 @@ impl<'a> Slider<'a> {
}
fn set_value_f32(&mut self, mut value: f32) {
if self.precision == 0 {
value = value.round();
}
value = round_to_precision(value, self.precision);
(self.get_set_value)(Some(value));
}
}

Loading…
Cancel
Save