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
use crate::{TitleBar, menu::items::MenuItem};
impl TitleBar {
/// Add a menu item to the title bar
///
/// Menu items are displayed in the title bar and can have optional callbacks.
///
/// # Arguments
/// * `label` - The text label for the menu item
/// * `callback` - Optional callback function to execute when clicked
///
/// # Examples
///
/// ```rust
/// title_bar.add_menu_item("File", None)
/// .add_menu_item("Save", Some(Box::new(|| println!("Save clicked!"))))
/// ```
pub fn add_menu_item(
mut self,
label: &str,
callback: Option<Box<dyn Fn() + Send + Sync>>,
) -> Self {
let index = self.menu_items.len();
self.menu_items.push((label.to_string(), callback));
self.menu_order.push((false, index)); // false = simple menu
self
}
/// Add a menu item with submenu support to the title bar
///
/// This method allows you to create dropdown menus with subitems that support
/// keyboard shortcuts, separators, and individual callbacks.
///
/// # Arguments
/// * `menu_item` - A MenuItem struct containing the menu label and subitems
///
/// # Examples
///
/// ```rust
/// let file_menu = MenuItem::new("File")
/// .add_subitem(SubMenuItem::new("New")
/// .with_shortcut(KeyboardShortcut::new("N").with_ctrl())
/// .with_callback(Box::new(|| println!("New file!"))))
/// .add_subitem(SubMenuItem::new("Open")
/// .with_shortcut(KeyboardShortcut::new("O").with_ctrl())
/// .with_callback(Box::new(|| println!("Open file!"))))
/// .add_subitem(SubMenuItem::new("Save")
/// .with_shortcut(KeyboardShortcut::new("S").with_ctrl())
/// .with_callback(Box::new(|| println!("Save file!")))
/// .with_separator())
/// .add_subitem(SubMenuItem::new("Exit").disabled());
///
/// title_bar.add_menu_with_submenu(file_menu);
/// ```
pub fn add_menu_with_submenu(mut self, menu_item: MenuItem) -> Self {
let index = self.menu_items_with_submenus.len();
self.menu_items_with_submenus.push(menu_item);
self.menu_order.push((true, index)); // true = submenu
self
}
}