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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//! Menu widgets, properties and other types.
//!
//! ```no_run
//! use zng::prelude::*;
//! # APP.defaults().run_window(async {
//!
//! fn main_menu() -> impl UiNode {
//! Menu!(ui_vec![
//! SubMenu!(
//! "File",
//! ui_vec![
//! Button!(zng::app::NEW_CMD.scoped(WINDOW.id())),
//! Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
//! Toggle! {
//! child = Text!("Auto Save");
//! checked = var(true);
//! },
//! Hr!(),
//! SubMenu!(
//! "Recent",
//! (0..10)
//! .map(|i| Button! { child = Text!(formatx!("recent file {i}")) })
//! .collect::<UiVec>()
//! ),
//! Hr!(),
//! Button!(zng::app::EXIT_CMD),
//! ]
//! ),
//! SubMenu!(
//! "Help",
//! ui_vec![Button! {
//! child = Text!("About");
//! on_click = hn!(|_| { });
//! }]
//! ),
//! ])
//! }
//!
//! Window! {
//! child_top = main_menu(), 0;
//! zng::app::on_new = hn!(|_| { });
//! zng::app::on_open = hn!(|_| { });
//! // ..
//! }
//! # });
//! ```
//!
//! The example above declares a [`Menu!`](struct@Menu) for a window, it demonstrates nested [`SubMenu!`](struct@sub::SubMenu),
//! and menu items, [`Button!`](struct@crate::button::Button),
//! [`Toggle!`](struct@crate::toggle::Toggle) and [`Hr!`](struct@crate::rule_line::hr::Hr). There is no menu item widget,
//! the `SubMenu!` widget re-styles button and toggle.
//!
//! # Context Menu
//!
//! This module also provides a context menu. The example below declares a context menu for the window, it will show
//! on context click, that is, by right-clicking the window, long pressing it or pressing the context menu key.
//!
//! ```
//! use zng::prelude::*;
//! # fn demo() {
//!
//! # let _ =
//! Window! {
//! context_menu = ContextMenu!(ui_vec![
//! Button!(zng::app::NEW_CMD.scoped(WINDOW.id())),
//! Button!(zng::app::OPEN_CMD.scoped(WINDOW.id())),
//! Toggle! {
//! child = Text!("Auto Save");
//! checked = var(true);
//! },
//! Hr!(),
//! SubMenu!("Help", ui_vec![Button! {
//! child = Text!("About");
//! on_click = hn!(|_| { });
//! }]),
//! Hr!(),
//! Button!(zng::app::EXIT_CMD),
//! ]);
//! }
//! # ; }
//! ```
//!
//! # Full API
//!
//! See [`zng_wgt_menu`] for the full widget API.
pub use zng_wgt_menu::{
icon, icon_fn, panel_fn, shortcut_spacing, shortcut_txt, style_fn, ButtonStyle, DefaultStyle, Menu, ToggleStyle, TouchButtonStyle,
};
/// Submenu widget and properties.
///
/// See [`zng_wgt_menu::sub`] for the full widget API.
pub mod sub {
pub use zng_wgt_menu::sub::{
column_width_padding, end_column, end_column_fn, end_column_width, hover_open_delay, is_open, start_column, start_column_fn,
start_column_width, DefaultStyle, SubMenu, SubMenuAncestors, SubMenuStyle, SubMenuWidgetInfoExt,
};
}
/// Context menu widget and properties.
///
/// See [`zng_wgt_menu::context`] for the full widget API.
pub mod context {
pub use zng_wgt_menu::context::{
context_menu, context_menu_anchor, context_menu_fn, disabled_context_menu, disabled_context_menu_fn, panel_fn, style_fn,
ContextMenu, ContextMenuArgs, DefaultStyle, TouchStyle,
};
}
/// Sub-menu popup widget and properties.
///
/// See [`zng_wgt_menu::popup`] for the full widget API.
pub mod popup {
pub use zng_wgt_menu::popup::{panel_fn, style_fn, DefaultStyle, SubMenuPopup};
}