winctx/menu_item.rs
1//! Types related to menu construction.
2
3use crate::{ItemId, ModifyMenuItem};
4
5pub(super) enum MenuItemKind {
6 Separator,
7 String { text: String },
8}
9
10/// A menu item in the context menu.
11///
12/// This is constructed through:
13/// * [`MenuItem::separator`].
14/// * [`MenuItem::entry`].
15pub struct MenuItem {
16 pub(crate) item_id: ItemId,
17 pub(crate) kind: MenuItemKind,
18 pub(crate) initial: ModifyMenuItem,
19}
20
21impl MenuItem {
22 pub(super) fn new(item_id: ItemId, kind: MenuItemKind) -> Self {
23 Self {
24 item_id,
25 kind,
26 initial: ModifyMenuItem::default(),
27 }
28 }
29
30 /// Get the identifier of the menu item.
31 pub fn id(&self) -> ItemId {
32 self.item_id
33 }
34
35 /// Set the checked state of the menu item.
36 ///
37 /// # Examples
38 ///
39 /// ```no_run
40 /// use winctx::CreateWindow;
41 ///
42 /// let mut window = CreateWindow::new("se.tedro.Example");;
43 /// let area = window.new_area();
44 ///
45 /// let mut menu = area.popup_menu();
46 /// menu.push_entry("Example Application").checked(true);
47 /// ```
48 pub fn checked(&mut self, checked: bool) -> &mut Self {
49 self.initial.checked(checked);
50 self
51 }
52
53 /// Set that the menu item should be highlighted.
54 ///
55 /// # Examples
56 ///
57 /// ```no_run
58 /// use winctx::CreateWindow;
59 ///
60 /// let mut window = CreateWindow::new("se.tedro.Example");;
61 /// let area = window.new_area();
62 ///
63 /// let mut menu = area.popup_menu();
64 /// menu.push_entry("Example Application").checked(true);
65 /// ```
66 pub fn highlight(&mut self, highlight: bool) -> &mut Self {
67 self.initial.highlight(highlight);
68 self
69 }
70}