1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use Key;

/// Command key on Mac OS
pub const MENU_KEY_COMMAND: usize = 1;
/// Windows key on Windows
pub const MENU_KEY_WIN: usize = 2;
/// Shift key
pub const MENU_KEY_SHIFT: usize = 4;
/// Control key
pub const MENU_KEY_CTRL: usize = 8;
/// Alt key
pub const MENU_KEY_ALT: usize = 16;

const MENU_ID_SEPARATOR:usize = 0xffffffff;

///
/// Used to hold the data for creating menus for the Application
///
pub struct Menu<'a> {
    /// Name of the menu item
    pub name: &'a str,
    /// User-defined Id thot will be sent back to the application in [get_menu_event]
    pub id: usize,
    /// Shortcut key for the menu item
    pub key: Key,
    /// Modifier on Windows for the menu
    pub modifier: usize,
    /// Modifier on Mac OS
    pub mac_mod: usize,
    /// Menu item should be enabled on grayed out
    pub enabled: bool,
    /// Sub-menu. Vector of a sub-menu, otherwise None if no sub-menu
    pub sub_menu: Option<&'a Vec<Menu<'a>>>,
}

impl<'a> Menu<'a> {
    pub fn separotor() -> Menu<'a> {
        Menu {
            id: MENU_ID_SEPARATOR,
            .. Self::default()
        }
    }
}

impl<'a> Default for Menu<'a> {
    fn default() -> Menu<'a> {
        Menu {
            name: "",
            id: 0,
            key: Key::Unknown,
            modifier: 0,
            mac_mod: 0,
            enabled: true,
            sub_menu: None,
        }
    }
}