1
/// Declares [`Role`] with its theme-file names from one list, so `ALL`, `name` and
2
/// `index` cannot disagree with the variants.
3
macro_rules! roles {
4
    ($($variant:ident => $name:literal),+ $(,)?) => {
5
        /// What a styled cell is for; the theme file assigns a style to each.
6
        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
7
        pub enum Role {
8
            $($variant),+
9
        }
10

            
11
        impl Role {
12
            pub const ALL: [Role; [$(Role::$variant),+].len()] = [$(Role::$variant),+];
13

            
14
            #[must_use]
15
10655661
            pub const fn name(self) -> &'static str {
16
10655661
                match self {
17
10655661
                    $(Role::$variant => $name),+
18
10655661
                }
19
10655661
            }
20
        }
21
    };
22
}
23

            
24
roles! {
25
    Menu => "menu",
26
    MenuSelected => "menu-selected",
27
    MenuHotkey => "menu-hotkey",
28
    MenuSelectedHotkey => "menu-selected-hotkey",
29
    MenuDisabled => "menu-disabled",
30
    MenuSelectedDisabled => "menu-selected-disabled",
31
    Panel => "panel",
32
    PanelFrame => "panel-frame",
33
    PanelFramePassive => "panel-frame-passive",
34
    PanelTitle => "panel-title",
35
    PanelHeader => "panel-header",
36
    PanelCursor => "panel-cursor",
37
    PanelDim => "panel-dim",
38
    FrameIcon => "frame-icon",
39
    Desktop => "desktop",
40
    Scrollbar => "scrollbar",
41
    ScrollbarThumb => "scrollbar-thumb",
42
    Status => "status",
43
    StatusHotkey => "status-hotkey",
44
    Dialog => "dialog",
45
    DialogFrame => "dialog-frame",
46
    DialogTitle => "dialog-title",
47
    DialogIcon => "dialog-icon",
48
    DialogFocus => "dialog-focus",
49
    Label => "label",
50
    LabelLit => "label-lit",
51
    Button => "button",
52
    ButtonDefault => "button-default",
53
    ButtonHotkey => "button-hotkey",
54
    ButtonFocus => "button-focus",
55
    ButtonShadow => "button-shadow",
56
    InputCursor => "input-cursor",
57
    Input => "input",
58
    InputFocused => "input-focused",
59
    InputArrow => "input-arrow",
60
    History => "history",
61
    HistoryArrow => "history-arrow",
62
    Prompt => "prompt",
63
    List => "list",
64
    ListSelected => "list-selected",
65
    Shadow => "shadow",
66
}
67

            
68
impl Role {
69
1177953
    pub(super) const fn index(self) -> usize {
70
1177953
        self as usize
71
1177953
    }
72

            
73
    #[must_use]
74
507473
    pub(crate) fn from_name(name: &str) -> Option<Role> {
75
10655616
        Self::ALL.into_iter().find(|role| role.name() == name)
76
507473
    }
77
}