windjammer_ui/components/generated/
contextmenu.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub struct ContextMenuItem {
6 label: String,
7 icon: String,
8 action: String,
9 disabled: bool,
10}
11
12impl ContextMenuItem {
13 #[inline]
14 pub fn new(label: String) -> ContextMenuItem {
15 ContextMenuItem {
16 label,
17 icon: String::from("".to_string()),
18 action: String::from("".to_string()),
19 disabled: false,
20 }
21 }
22 #[inline]
23 pub fn icon(mut self, icon: String) -> ContextMenuItem {
24 self.icon = icon;
25 self
26 }
27 #[inline]
28 pub fn action(mut self, action: String) -> ContextMenuItem {
29 self.action = action;
30 self
31 }
32 #[inline]
33 pub fn disabled(mut self, disabled: bool) -> ContextMenuItem {
34 self.disabled = disabled;
35 self
36 }
37}
38
39pub struct ContextMenu {
40 items: Vec<ContextMenuItem>,
41 trigger_id: String,
42}
43
44impl ContextMenu {
45 #[inline]
46 pub fn new(trigger_id: String) -> ContextMenu {
47 ContextMenu {
48 items: Vec::new(),
49 trigger_id,
50 }
51 }
52 #[inline]
53 pub fn item(mut self, item: ContextMenuItem) -> ContextMenu {
54 self.items.push(item);
55 self
56 }
57}
58
59impl Renderable for ContextMenu {
60 #[inline]
61 fn render(self) -> String {
62 let mut items_html = Vec::new();
63 for item in &self.items {
64 let icon_html = {
65 if item.icon.len() > 0 {
66 format!("<span class='wj-context-icon'>{}</span>", item.icon)
67 } else {
68 String::from("".to_string())
69 }
70 };
71 let disabled_class = {
72 if item.disabled {
73 " wj-context-item-disabled"
74 } else {
75 ""
76 }
77 };
78 let disabled_attr = {
79 if item.disabled {
80 " disabled"
81 } else {
82 ""
83 }
84 };
85 items_html.push(format!(
86 "<button class='wj-context-item{}' onclick='{}'{}>
87 {}
88 <span>{}</span>
89 </button>",
90 disabled_class, item.action, disabled_attr, icon_html, item.label
91 ));
92 }
93 format!(
94 "<div class='wj-context-menu' id='context-{}' style='display: none'>
95 {}
96 </div>",
97 self.trigger_id,
98 items_html.join("")
99 )
100 }
101}