Skip to content

Commit

Permalink
Fix moving slider with arrow keys (#3354)
Browse files Browse the repository at this point in the history
It would sometimes get stuck on the same value due to "smart-aim"
  • Loading branch information
emilk authored Sep 18, 2023
1 parent ceb8723 commit fea9047
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,14 @@ impl<'a> Slider<'a> {
let kb_step = increment as f32 - decrement as f32;

if kb_step != 0.0 {
let ui_point_per_step = 1.0; // move this many ui points for each kb_step
let prev_value = self.get_value();
let prev_position = self.position_from_value(prev_value, position_range);
let new_position = prev_position + kb_step;
let new_position = prev_position + ui_point_per_step * kb_step;
let new_value = match self.step {
Some(step) => prev_value + (kb_step as f64 * step),
None if self.smart_aim => {
let aim_radius = ui.input(|i| i.aim_radius());
let aim_radius = 0.49 * ui_point_per_step; // Chosen so we don't include `prev_value` in the search.
emath::smart_aim::best_in_range_f64(
self.value_from_position(new_position - aim_radius, position_range),
self.value_from_position(new_position + aim_radius, position_range),
Expand Down

0 comments on commit fea9047

Please sign in to comment.