makepad_widget/windowmenu.rs
1// a window menu implementation
2use makepad_render::*;
3use crate::widgetstyle::*;
4
5#[derive(Clone)]
6pub struct WindowMenu {
7 pub view: View,
8 pub item_draw: MenuItemDraw,
9}
10
11#[derive(Clone)]
12pub struct MenuItemDraw {
13 pub text: Text,
14 pub item_bg: Quad,
15 //pub item_layout: LayoutId,
16 //pub name_color: ColorId,
17 //pub bg_color: ColorId,
18 //pub bg_over_color: ColorId,
19 //pub bg_selected_color: ColorId,
20}
21
22impl MenuItemDraw {
23 pub fn proto(cx: &mut Cx) -> Self {
24 Self {
25 text: Text {
26 wrapping: Wrapping::Word,
27 ..Text::proto(cx)
28 },
29 //item_layout: Layout_window_menu::id(cx),
30 item_bg: Quad::proto(cx),
31 //name_color: Color_text_selected_focus::id(cx),
32 //bg_color: Color_bg_selected::id(cx),
33 //bg_over_color: Color_bg_odd::id(cx),
34 //bg_selected_color: Color_bg_selected_over::id(cx),
35 }
36 }
37
38 pub fn get_default_anim(&self, cx: &Cx) -> Anim {
39 Anim::new(Play::Chain {duration: 0.01}, vec![
40 Track::color(Quad::instance_color(), Ease::Lin, vec![
41 (1.0, Theme::color_bg_selected().get(cx))
42 ])
43 ])
44 }
45
46 pub fn get_default_anim_cut(&self, cx: &Cx) -> Anim {
47 Anim::new(Play::Cut {duration: 0.01}, vec![
48 Track::color(Quad::instance_color(), Ease::Lin, vec![
49 (0.0, Theme::color_bg_selected().get(cx))
50 ])
51 ])
52 }
53
54 pub fn get_over_anim(&self, cx: &Cx) -> Anim {
55 Anim::new(Play::Cut {duration: 0.02}, vec![
56 Track::color(Quad::instance_color(), Ease::Lin, vec![
57 (0., Theme::color_bg_odd().get(cx)),
58 ])
59 ])
60 }
61
62 pub fn text_style_menu_label() ->TextStyleId{uid!()}
63
64 pub fn style(cx:&mut Cx, _opt:&StyleOptions){
65 Self::text_style_menu_label().set(cx, Theme::text_style_normal().get(cx));
66 }
67
68 /*
69 pub fn draw_log_path(&mut self, cx: &mut Cx, path: &str, row: usize) {
70 self.text.color = self.path_color;
71 self.text.draw_text(cx, &format!("{}:{} - ", path, row));
72 }
73
74 pub fn draw_log_body(&mut self, cx: &mut Cx, body: &str) {
75 self.text.color = self.message_color;
76 if body.len()>500 {
77 self.text.draw_text(cx, &body[0..500]);
78 }
79 else {
80 self.text.draw_text(cx, &body);
81 }
82 }
83
84 pub fn draw_log_item(&mut self, cx: &mut Cx, list_item: &mut ListItem, log_item: &HubLogItem) {
85 self.item_bg.color = list_item.animator.last_color(cx.id("bg.color"));
86 let bg_inst = self.item_bg.begin_quad(cx, &self.get_line_layout());
87
88 match log_item {
89 HubLogItem::LocPanic(loc_msg) => {
90 self.code_icon.draw_icon_walk(cx, CodeIconType::Panic);
91 self.draw_log_path(cx, &loc_msg.path, loc_msg.row);
92 self.draw_log_body(cx, &loc_msg.body);
93
94 },
95 HubLogItem::LocError(loc_msg) => {
96 self.code_icon.draw_icon_walk(cx, CodeIconType::Error);
97 self.draw_log_path(cx, &loc_msg.path, loc_msg.row);
98 self.draw_log_body(cx, &loc_msg.body);
99 },
100 HubLogItem::LocWarning(loc_msg) => {
101 self.code_icon.draw_icon_walk(cx, CodeIconType::Warning);
102 self.draw_log_path(cx, &loc_msg.path, loc_msg.row);
103 self.draw_log_body(cx, &loc_msg.body);
104 },
105 HubLogItem::LocMessage(loc_msg) => {
106 self.draw_log_path(cx, &loc_msg.path, loc_msg.row);
107 self.draw_log_body(cx, &loc_msg.body);
108 },
109 HubLogItem::Error(msg) => {
110 self.code_icon.draw_icon_walk(cx, CodeIconType::Error);
111 self.draw_log_body(cx, &msg);
112 },
113 HubLogItem::Warning(msg) => {
114 self.code_icon.draw_icon_walk(cx, CodeIconType::Warning);
115 self.draw_log_body(cx, &msg);
116 },
117 HubLogItem::Message(msg) => {
118 self.draw_log_body(cx, &msg);
119 }
120 }
121
122 let bg_area = self.item_bg.end_quad(cx, &bg_inst);
123 list_item.animator.update_area_refs(cx, bg_area);
124 }*/
125}
126
127#[derive(Clone)]
128pub enum WindowMenuEvent {
129 SelectItem {
130 },
131 None,
132}
133
134impl WindowMenu {
135 pub fn proto(cx: &mut Cx) -> Self {
136 Self {
137 item_draw: MenuItemDraw::proto(cx),
138 view: View::proto(cx),
139 }
140 }
141
142 pub fn handle_window_menu(&mut self, _cx: &mut Cx, _event: &mut Event, _menu: &Menu) -> WindowMenuEvent {
143 WindowMenuEvent::None
144 }
145
146 pub fn draw_window_menu(&mut self, _cx: &mut Cx, _menu: &Menu) {
147 }
148}