Expand description
Menu widgets, properties and other types.
use zng::prelude::*;
fn main_menu() -> 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}"));
})
),
Hr!(),
Button!(zng::app::EXIT_CMD),
]
),
SubMenu!(
"Help",
ui_vec![Button! {
child = Text!("About");
on_click = hn!(|_| {});
}]
),
])
}
Window! {
child_top = main_menu();
zng::app::on_new = hn!(|_| {});
zng::app::on_open = hn!(|_| {});
// ..
}The example above declares a Menu! for a window, it demonstrates nested SubMenu!,
and menu items, Button!,
Toggle! and 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::*;
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.
Modules§
- context
- Context menu widget and properties.
- popup
- Sub-menu popup widget and properties.
- sub
- Submenu widget and properties.
Structs§
- Button
Style WStyle applied to allButton!widgets insideMenu!root.- Default
Style WDefaultMenu!style.- Icon
Button Style WAlternate style for buttons inside a menu.- Menu
WMenu root panel.- Text
Input Style WStyle applied to allTextInput!widgets insideMenu!root.- Toggle
Style WStyle applied to allToggle!widgets insideMenu!root.
Functions§
- icon
PMenu item icon.- icon_fn
PMenu item icon from widget function.- panel_
fn PWidget function that generates the menu layout.- shortcut_
txt PMenu item shortcut text.- style_
fn PExtends or replaces the widget style.