diff options
author | 2023-07-31 22:59:42 +0200 | |
---|---|---|
committer | 2023-07-31 22:59:42 +0200 | |
commit | 32a95171d2c2a7a7ac8c141277b8c3555dbb3e77 (patch) | |
tree | 4c1119fedfa728785b13b54fc5114d835e08a5d3 /widget/src/combo_box.rs | |
parent | 50ce65b3b7ad10a8537b751b3890d9dcfaecf846 (diff) | |
download | iced-32a95171d2c2a7a7ac8c141277b8c3555dbb3e77.tar.gz iced-32a95171d2c2a7a7ac8c141277b8c3555dbb3e77.tar.bz2 iced-32a95171d2c2a7a7ac8c141277b8c3555dbb3e77.zip |
cycle combobox with keybinds
Diffstat (limited to 'widget/src/combo_box.rs')
-rw-r--r-- | widget/src/combo_box.rs | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 93fc92b9..c9397433 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -468,11 +468,13 @@ where if let Event::Keyboard(keyboard::Event::KeyPressed { key_code, + modifiers, .. }) = event { - match key_code { - keyboard::KeyCode::Enter => { + let shift_modifer = modifiers.shift(); + match (key_code, shift_modifer) { + (keyboard::KeyCode::Enter, _) => { if let Some(index) = &menu.hovered_option { if let Some(option) = state.filtered_options.options.get(*index) @@ -483,9 +485,19 @@ where event_status = event::Status::Captured; } - keyboard::KeyCode::Up => { + + (keyboard::KeyCode::Up, _) + | (keyboard::KeyCode::Tab, true) => { if let Some(index) = &mut menu.hovered_option { - *index = index.saturating_sub(1); + if *index == 0 { + *index = state + .filtered_options + .options + .len() + .saturating_sub(1); + } else { + *index = index.saturating_sub(1); + } } else { menu.hovered_option = Some(0); } @@ -511,15 +523,28 @@ where event_status = event::Status::Captured; } - keyboard::KeyCode::Down => { + (keyboard::KeyCode::Down, _) + | (keyboard::KeyCode::Tab, false) + if !modifiers.shift() => + { if let Some(index) = &mut menu.hovered_option { - *index = index.saturating_add(1).min( - state + if *index + == state .filtered_options .options .len() - .saturating_sub(1), - ); + .saturating_sub(1) + { + *index = 0; + } else { + *index = index.saturating_add(1).min( + state + .filtered_options + .options + .len() + .saturating_sub(1), + ); + } } else { menu.hovered_option = Some(0); } |