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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user