How to adjust the slider's decimals? #4670
-
I use: ui.add(
Slider::new(&mut ctx.components.setting.ai.temperature, 0_f32..=2.)
.fixed_decimals(1)
.step_by(0.1),
); The display shows |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
You're using an Try changing the type of |
Beta Was this translation helpful? Give feedback.
-
This sounds like a problem with your serializer, not with egui. Does the problem still persist if you assing |
Beta Was this translation helpful? Give feedback.
-
Things quite clear now. If I use f32 with the slider, the slider can get the value correctly. But toml has this issue toml-rs/toml#494. If I use f64 with the slider, the toml can serialize the value correctly. But egui can not get the value correctly. |
Beta Was this translation helpful? Give feedback.
-
When a step is set, the slider does some arithmetic on the value after rounding it, which causes these rounding errors: egui/crates/egui/src/widgets/slider.rs Lines 538 to 544 in db8db50 It is pretty easy to reproduce: ui.add(
egui::Slider::new(&mut self.value, 0.0..=2.0)
.max_decimals(2)
.step_by(0.1),
);
ui.label(self.value.to_string()); It is the same effect whether we change the value with the slider, the drag functionality or just type it manually. If we invert the order of the two So if there are no undesirable side effects, this could be an easy fix. I'll try to look into it and make a PR this week if no one does it first. |
Beta Was this translation helpful? Give feedback.
When a step is set, the slider does some arithmetic on the value after rounding it, which causes these rounding errors:
egui/crates/egui/src/widgets/slider.rs
Lines 538 to 544 in db8db50
It is pretty easy to reproduce: