1macro_rules! roles {
4 ($($variant:ident => $name:literal),+ $(,)?) => {
5 #[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 pub const fn name(self) -> &'static str {
16 match self {
17 $(Role::$variant => $name),+
18 }
19 }
20 }
21 };
22}
23
24roles! {
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
68impl Role {
69 pub(super) const fn index(self) -> usize {
70 self as usize
71 }
72
73 #[must_use]
74 pub(crate) fn from_name(name: &str) -> Option<Role> {
75 Self::ALL.into_iter().find(|role| role.name() == name)
76 }
77}