ferroui_base/input/
navigation_direction.rs1use super::{Key, KeyModifiers};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
5pub enum NavigationDirection {
6 Next,
8 Previous,
10 First,
12 Last,
14 Left,
16 Right,
18 Up,
20 Down,
22 PageUp,
24 PageDown,
26}
27
28impl NavigationDirection {
29 pub fn is_tab(self) -> bool {
31 self == NavigationDirection::Next || self == NavigationDirection::Previous
32 }
33
34 pub fn is_directional(self) -> bool {
36 self > NavigationDirection::Previous && self <= NavigationDirection::PageDown
37 }
38}
39
40impl Key {
41 pub fn to_navigation_direction(self, modifiers: KeyModifiers) -> Option<NavigationDirection> {
44 match self {
45 Key::Tab => Some(if !modifiers.contains(KeyModifiers::SHIFT) {
46 NavigationDirection::Next
47 } else {
48 NavigationDirection::Previous
49 }),
50 Key::Up => Some(NavigationDirection::Up),
51 Key::Down => Some(NavigationDirection::Down),
52 Key::Left => Some(NavigationDirection::Left),
53 Key::Right => Some(NavigationDirection::Right),
54 Key::Home => Some(NavigationDirection::First),
55 Key::End => Some(NavigationDirection::Last),
56 Key::PageUp => Some(NavigationDirection::PageUp),
57 Key::PageDown => Some(NavigationDirection::PageDown),
58 _ => None,
59 }
60 }
61}