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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use {
crate::{
makepad_live_id::LiveId,
event::KeyCode
},
};
#[derive(Clone, Copy, Default)]
pub struct CxCommandSetting {
pub shift: bool,
pub key_code: KeyCode,
pub enabled: bool
}
// Command
#[derive(Clone, Debug, Default, Eq, Hash, Copy, PartialEq)]
pub struct MenuCommand(pub LiveId);
impl From<LiveId> for MenuCommand {
fn from(live_id: LiveId) -> MenuCommand {MenuCommand(live_id)}
}
impl MenuCommand{
//pub fn from_id(id:LiveId)->Self{Self(id.0)}
/*
pub fn set_enabled(&self, cx:&mut Cx, enabled:bool)->Self{
let mut s = if let Some(s) = cx.command_settings.get(self){*s}else{CxCommandSetting::default()};
s.enabled = enabled;
cx.command_settings.insert(*self, s);
*self
}
pub fn set_key(&self, cx:&mut Cx, key_code:KeyCode)->Self{
let mut s = if let Some(s) = cx.command_settings.get(self){*s}else{CxCommandSetting::default()};
s.shift = false;
s.key_code = key_code;
cx.command_settings.insert(*self, s);
*self
}
pub fn set_key_shift(&self, cx:&mut Cx, key_code:KeyCode)->Self{
let mut s = if let Some(s) = cx.command_settings.get(self){*s}else{CxCommandSetting::default()};
s.shift = true;
s.key_code = key_code;
cx.command_settings.insert(*self, s);
*self
}*/
}
#[derive(PartialEq, Clone)]
pub enum Menu {
Main {items:Vec<Menu>},
Item {name: String, command:MenuCommand},
Sub {name: String, items: Vec<Menu>},
Line
}
impl Menu {
pub fn main(items: Vec<Menu>)->Menu{
Menu::Main{items:items}
}
pub fn sub(name: &str, items: Vec<Menu>) -> Menu {
Menu::Sub {
name: name.to_string(),
items: items
}
}
pub fn line() -> Menu {
Menu::Line
}
pub fn item(name: &str, command: MenuCommand) -> Menu {
Menu::Item {
name: name.to_string(),
command: command
}
}
}