zng/menu.rs
1#![cfg(feature = "menu")]
2
3//! Menu widgets, properties and other types.
4//!
5//! ```no_run
6//! use zng::prelude::*;
7//! # APP.defaults().run_window(async {
8//!
9//! fn main_menu() -> impl UiNode {
10//! Menu!(ui_vec![
11//! SubMenu!(
12//! "File",
13//! ui_vec![
14//! Button!(zng::app::NEW_CMD.scoped(WINDOW.id())),
15//! Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
16//! Toggle! {
17//! child = Text!("Auto Save");
18//! checked = var(true);
19//! },
20//! Hr!(),
21//! SubMenu!(
22//! "Recent",
23//! (0..10)
24//! .map(|i| Button! { child = Text!(formatx!("recent file {i}")) })
25//! .collect::<UiVec>()
26//! ),
27//! Hr!(),
28//! Button!(zng::app::EXIT_CMD),
29//! ]
30//! ),
31//! SubMenu!(
32//! "Help",
33//! ui_vec![Button! {
34//! child = Text!("About");
35//! on_click = hn!(|_| { });
36//! }]
37//! ),
38//! ])
39//! }
40//!
41//! Window! {
42//! child_top = main_menu(), 0;
43//! zng::app::on_new = hn!(|_| { });
44//! zng::app::on_open = hn!(|_| { });
45//! // ..
46//! }
47//! # });
48//! ```
49//!
50//! The example above declares a [`Menu!`](struct@Menu) for a window, it demonstrates nested [`SubMenu!`](struct@sub::SubMenu),
51//! and menu items, [`Button!`](struct@crate::button::Button),
52//! [`Toggle!`](struct@crate::toggle::Toggle) and [`Hr!`](struct@crate::rule_line::hr::Hr). There is no menu item widget,
53//! the `SubMenu!` widget re-styles button and toggle.
54//!
55//! # Context Menu
56//!
57//! This module also provides a context menu. The example below declares a context menu for the window, it will show
58//! on context click, that is, by right-clicking the window, long pressing it or pressing the context menu key.
59//!
60//! ```
61//! use zng::prelude::*;
62//! # fn demo() {
63//!
64//! # let _ =
65//! Window! {
66//! context_menu = ContextMenu!(ui_vec![
67//! Button!(zng::app::NEW_CMD.scoped(WINDOW.id())),
68//! Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
69//! Toggle! {
70//! child = Text!("Auto Save");
71//! checked = var(true);
72//! },
73//! Hr!(),
74//! SubMenu!("Help", ui_vec![Button! {
75//! child = Text!("About");
76//! on_click = hn!(|_| { });
77//! }]),
78//! Hr!(),
79//! Button!(zng::app::EXIT_CMD),
80//! ]);
81//! }
82//! # ; }
83//! ```
84//!
85//! # Full API
86//!
87//! See [`zng_wgt_menu`] for the full widget API.
88
89pub use zng_wgt_menu::{
90 ButtonStyle, DefaultStyle, Menu, ToggleStyle, TouchButtonStyle, icon, icon_fn, panel_fn, shortcut_spacing, shortcut_txt, style_fn,
91};
92
93/// Submenu widget and properties.
94///
95/// See [`zng_wgt_menu::sub`] for the full widget API.
96pub mod sub {
97 pub use zng_wgt_menu::sub::{
98 DefaultStyle, SubMenu, SubMenuAncestors, SubMenuStyle, SubMenuWidgetInfoExt, column_width_padding, end_column, end_column_fn,
99 end_column_width, hover_open_delay, is_open, start_column, start_column_fn, start_column_width,
100 };
101}
102
103/// Context menu widget and properties.
104///
105/// See [`zng_wgt_menu::context`] for the full widget API.
106pub mod context {
107 pub use zng_wgt_menu::context::{
108 ContextMenu, ContextMenuArgs, DefaultStyle, TouchStyle, context_menu, context_menu_anchor, context_menu_fn, disabled_context_menu,
109 disabled_context_menu_fn, panel_fn, style_fn,
110 };
111}
112
113/// Sub-menu popup widget and properties.
114///
115/// See [`zng_wgt_menu::popup`] for the full widget API.
116pub mod popup {
117 pub use zng_wgt_menu::popup::{DefaultStyle, SubMenuPopup, panel_fn, style_fn};
118}