Skip to main content

glory_render/
navigation_panel.rs

1//! Navigation disclosure commands, separate from action-menu roles.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum NavigationPanel {
4    Trigger,
5    Content,
6}
7impl NavigationPanel {
8    pub fn as_str(self) -> &'static str {
9        match self {
10            Self::Trigger => "trigger",
11            Self::Content => "content",
12        }
13    }
14}
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16pub enum NavigationPanelCommand {
17    First,
18    Last,
19    Open,
20    Close,
21}
22impl crate::KeyboardInput<'_> {
23    /// `inside` means the physical control belongs to a mounted content level.
24    /// Tab stays native; hover and Escape/outside dismissal use separate protocols.
25    pub fn navigation_panel(
26        self,
27        direction: crate::Direction,
28        trigger: bool,
29        inside: bool,
30    ) -> Option<NavigationPanelCommand> {
31        if self.composing || self.editable || self.control || self.meta || self.alt || self.shift {
32            return None;
33        }
34        match (trigger, inside, direction, self.key) {
35            (true, false, _, "ArrowDown") => Some(NavigationPanelCommand::First),
36            (true, false, _, "ArrowUp") => Some(NavigationPanelCommand::Last),
37            (true, true, crate::Direction::Ltr, "ArrowRight")
38            | (true, true, crate::Direction::Rtl, "ArrowLeft") => {
39                Some(NavigationPanelCommand::Open)
40            }
41            (_, true, crate::Direction::Ltr, "ArrowLeft")
42            | (_, true, crate::Direction::Rtl, "ArrowRight") => Some(NavigationPanelCommand::Close),
43            _ => None,
44        }
45    }
46}