From a6ab126e477e9cd8e5b548c9d02dd2751b57d04c Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 15 Jul 2024 16:28:45 +0800 Subject: [PATCH] Slider: round to decimals after applying `step_by` (#4822) * Closes https://github.com/emilk/egui/discussions/4670 * [x] I have followed the instructions in the PR template --- crates/egui/src/widgets/slider.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/widgets/slider.rs b/crates/egui/src/widgets/slider.rs index d3c9dc94..84e47aee 100644 --- a/crates/egui/src/widgets/slider.rs +++ b/crates/egui/src/widgets/slider.rs @@ -536,13 +536,13 @@ impl<'a> Slider<'a> { let end = *self.range.end(); value = value.clamp(start.min(end), start.max(end)); } - if let Some(max_decimals) = self.max_decimals { - value = emath::round_to_decimals(value, max_decimals); - } if let Some(step) = self.step { let start = *self.range.start(); value = start + ((value - start) / step).round() * step; } + if let Some(max_decimals) = self.max_decimals { + value = emath::round_to_decimals(value, max_decimals); + } set(&mut self.get_set_value, value); }