1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

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

This commit is contained in:
Emil Ernerfeldt
2020-06-10 16:22:31 +02:00
parent 3c85c2d364
commit 2162ffff42
2 changed files with 8 additions and 3 deletions

View File

@@ -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)
}

View File

@@ -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));
}
}