Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moving slider with arrow keys #3354

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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