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
//! Types related to menu construction.
use crate::{ItemId, ModifyMenuItem};
pub(super) enum MenuItemKind {
Separator,
String { text: String },
}
/// A menu item in the context menu.
///
/// This is constructed through:
/// * [`MenuItem::separator`].
/// * [`MenuItem::entry`].
pub struct MenuItem {
pub(crate) item_id: ItemId,
pub(crate) kind: MenuItemKind,
pub(crate) initial: ModifyMenuItem,
}
impl MenuItem {
pub(super) fn new(item_id: ItemId, kind: MenuItemKind) -> Self {
Self {
item_id,
kind,
initial: ModifyMenuItem::default(),
}
}
/// Get the identifier of the menu item.
pub fn id(&self) -> ItemId {
self.item_id
}
/// Set the checked state of the menu item.
///
/// # Examples
///
/// ```no_run
/// use winctx::CreateWindow;
///
/// let mut window = CreateWindow::new("se.tedro.Example");;
/// let area = window.new_area();
///
/// let mut menu = area.popup_menu();
/// menu.push_entry("Example Application").checked(true);
/// ```
pub fn checked(&mut self, checked: bool) -> &mut Self {
self.initial.checked(checked);
self
}
/// Set that the menu item should be highlighted.
///
/// # Examples
///
/// ```no_run
/// use winctx::CreateWindow;
///
/// let mut window = CreateWindow::new("se.tedro.Example");;
/// let area = window.new_area();
///
/// let mut menu = area.popup_menu();
/// menu.push_entry("Example Application").checked(true);
/// ```
pub fn highlight(&mut self, highlight: bool) -> &mut Self {
self.initial.highlight(highlight);
self
}
}