diff options
author | 2021-07-22 21:38:22 +0700 | |
---|---|---|
committer | 2021-07-22 21:38:22 +0700 | |
commit | dc0b96ce407283f2ffd9add5ad339f89097555d3 (patch) | |
tree | f17df1cd95d2d4c77db4f8783b433d8a7b8bf1a6 /native | |
parent | 587dbbca421bc4b81f883aada063bf854c45f773 (diff) | |
parent | 46aab24d91eb083a2f030094e33f98ba8e0dad7f (diff) | |
download | iced-dc0b96ce407283f2ffd9add5ad339f89097555d3.tar.gz iced-dc0b96ce407283f2ffd9add5ad339f89097555d3.tar.bz2 iced-dc0b96ce407283f2ffd9add5ad339f89097555d3.zip |
Merge pull request #872 from 13r0ck/master
add scrolling to pick_lists
Diffstat (limited to '')
-rw-r--r-- | native/src/widget/pick_list.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 4f4e751e..f4b60fc4 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -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, } } |