Skip to content

Commit

Permalink
Merge pull request #872 from 13r0ck/master
Browse files Browse the repository at this point in the history
add scrolling to pick_lists
  • Loading branch information
hecrj authored Jul 22, 2021
2 parents 587dbbc + 46aab24 commit dc0b96c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions native/src/widget/pick_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,43 @@ where
event_status
}
}
Event::Mouse(mouse::Event::WheelScrolled {
delta: mouse::ScrollDelta::Lines { y, .. },
}) if layout.bounds().contains(cursor_position)
&& !*self.is_open =>
{
fn find_next<'a, T: PartialEq>(
selected: &'a T,
mut options: impl Iterator<Item = &'a T>,
) -> Option<&'a T> {
let _ = options.find(|&option| option == selected);

options.next()
}

let next_option = if y < 0.0 {
if let Some(selected) = self.selected.as_ref() {
find_next(selected, self.options.iter())
} else {
self.options.first()
}
} else if y > 0.0 {
if let Some(selected) = self.selected.as_ref() {
find_next(selected, self.options.iter().rev())
} else {
self.options.last()
}
} else {
None
};

if let Some(next_option) = next_option {
messages.push((self.on_selected)(next_option.clone()));
}

return event::Status::Captured;
}

_ => event::Status::Ignored,
}
}
Expand Down

0 comments on commit dc0b96c

Please sign in to comment.