Merge pull request #966 from hecrj/pick-list-scroll-modifier
Allow `PickList` selection with mouse scroll only if command is pressed
This commit is contained in:
commit
f94b50021d
1 changed files with 13 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
//! Display a dropdown list of selectable values.
|
//! Display a dropdown list of selectable values.
|
||||||
use crate::event::{self, Event};
|
use crate::event::{self, Event};
|
||||||
|
use crate::keyboard;
|
||||||
use crate::layout;
|
use crate::layout;
|
||||||
use crate::mouse;
|
use crate::mouse;
|
||||||
use crate::overlay;
|
use crate::overlay;
|
||||||
|
|
@ -20,6 +21,7 @@ where
|
||||||
[T]: ToOwned<Owned = Vec<T>>,
|
[T]: ToOwned<Owned = Vec<T>>,
|
||||||
{
|
{
|
||||||
menu: &'a mut menu::State,
|
menu: &'a mut menu::State,
|
||||||
|
keyboard_modifiers: &'a mut keyboard::Modifiers,
|
||||||
is_open: &'a mut bool,
|
is_open: &'a mut bool,
|
||||||
hovered_option: &'a mut Option<usize>,
|
hovered_option: &'a mut Option<usize>,
|
||||||
last_selection: &'a mut Option<T>,
|
last_selection: &'a mut Option<T>,
|
||||||
|
|
@ -38,6 +40,7 @@ where
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct State<T> {
|
pub struct State<T> {
|
||||||
menu: menu::State,
|
menu: menu::State,
|
||||||
|
keyboard_modifiers: keyboard::Modifiers,
|
||||||
is_open: bool,
|
is_open: bool,
|
||||||
hovered_option: Option<usize>,
|
hovered_option: Option<usize>,
|
||||||
last_selection: Option<T>,
|
last_selection: Option<T>,
|
||||||
|
|
@ -47,6 +50,7 @@ impl<T> Default for State<T> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
menu: menu::State::default(),
|
menu: menu::State::default(),
|
||||||
|
keyboard_modifiers: keyboard::Modifiers::default(),
|
||||||
is_open: bool::default(),
|
is_open: bool::default(),
|
||||||
hovered_option: Option::default(),
|
hovered_option: Option::default(),
|
||||||
last_selection: Option::default(),
|
last_selection: Option::default(),
|
||||||
|
|
@ -71,6 +75,7 @@ where
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let State {
|
let State {
|
||||||
menu,
|
menu,
|
||||||
|
keyboard_modifiers,
|
||||||
is_open,
|
is_open,
|
||||||
hovered_option,
|
hovered_option,
|
||||||
last_selection,
|
last_selection,
|
||||||
|
|
@ -78,6 +83,7 @@ where
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
menu,
|
menu,
|
||||||
|
keyboard_modifiers,
|
||||||
is_open,
|
is_open,
|
||||||
hovered_option,
|
hovered_option,
|
||||||
last_selection,
|
last_selection,
|
||||||
|
|
@ -270,7 +276,8 @@ where
|
||||||
}
|
}
|
||||||
Event::Mouse(mouse::Event::WheelScrolled {
|
Event::Mouse(mouse::Event::WheelScrolled {
|
||||||
delta: mouse::ScrollDelta::Lines { y, .. },
|
delta: mouse::ScrollDelta::Lines { y, .. },
|
||||||
}) if layout.bounds().contains(cursor_position)
|
}) if self.keyboard_modifiers.command()
|
||||||
|
&& layout.bounds().contains(cursor_position)
|
||||||
&& !*self.is_open =>
|
&& !*self.is_open =>
|
||||||
{
|
{
|
||||||
fn find_next<'a, T: PartialEq>(
|
fn find_next<'a, T: PartialEq>(
|
||||||
|
|
@ -302,9 +309,13 @@ where
|
||||||
messages.push((self.on_selected)(next_option.clone()));
|
messages.push((self.on_selected)(next_option.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return event::Status::Captured;
|
event::Status::Captured
|
||||||
}
|
}
|
||||||
|
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => {
|
||||||
|
*self.keyboard_modifiers = modifiers;
|
||||||
|
|
||||||
|
event::Status::Ignored
|
||||||
|
}
|
||||||
_ => event::Status::Ignored,
|
_ => event::Status::Ignored,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue