Skip to content

Commit

Permalink
Merge pull request #2565 from kiedtl/slider_mouse_wheel
Browse files Browse the repository at this point in the history
slider: handle mouse wheel events
  • Loading branch information
hecrj authored Sep 13, 2024
2 parents 0c50280 + 83041f6 commit f3b51e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 19 additions & 1 deletion widget/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,26 @@ where
return event::Status::Captured;
}
}
Event::Mouse(mouse::Event::WheelScrolled { delta })
if state.keyboard_modifiers.control() =>
{
if cursor.is_over(layout.bounds()) {
let delta = match delta {
mouse::ScrollDelta::Lines { x: _, y } => y,
mouse::ScrollDelta::Pixels { x: _, y } => y,
};

if delta < 0.0 {
let _ = decrement(current_value).map(change);
} else {
let _ = increment(current_value).map(change);
}

return event::Status::Captured;
}
}
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
if cursor.position_over(layout.bounds()).is_some() {
if cursor.is_over(layout.bounds()) {
match key {
Key::Named(key::Named::ArrowUp) => {
let _ = increment(current_value).map(change);
Expand Down
20 changes: 19 additions & 1 deletion widget/src/vertical_slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,26 @@ where
return event::Status::Captured;
}
}
Event::Mouse(mouse::Event::WheelScrolled { delta })
if state.keyboard_modifiers.control() =>
{
if cursor.is_over(layout.bounds()) {
let delta = match delta {
mouse::ScrollDelta::Lines { x: _, y } => y,
mouse::ScrollDelta::Pixels { x: _, y } => y,
};

if delta < 0.0 {
let _ = decrement(current_value).map(change);
} else {
let _ = increment(current_value).map(change);
}

return event::Status::Captured;
}
}
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
if cursor.position_over(layout.bounds()).is_some() {
if cursor.is_over(layout.bounds()) {
match key {
Key::Named(key::Named::ArrowUp) => {
let _ = increment(current_value).map(change);
Expand Down

0 comments on commit f3b51e4

Please sign in to comment.