Add comments to menubar example

This commit is contained in:
Alexandre Bury 2016-10-09 15:56:03 -07:00
parent 44dbd5826e
commit 90c9d51a6c
2 changed files with 20 additions and 7 deletions

View File

@ -1,25 +1,35 @@
extern crate cursive;
use cursive::Cursive;
use cursive::menu::MenuTree;
use cursive::views::{Dialog, TextView};
use cursive::event::Key;
use cursive::menu::MenuTree;
use cursive::traits::*;
use cursive::views::Dialog;
fn main() {
let mut siv = Cursive::new();
// The menubar is a list of (label, menu tree) pairs.
siv.menubar()
// We add a new "File" tree
.add("File",
MenuTree::new()
// Trees are made of leaves, with are directly actionable...
.leaf("New", |s| s.add_layer(Dialog::info("New file!")))
// ... and of sub-trees, which open up when selected.
.subtree("Recent",
// The `.with()` method can help when running loops
// within builder patterns.
MenuTree::new().with(|tree| {
for i in 1..100 {
// We don't actually do anything here,
// but you could!
tree.add_leaf(&format!("Item {}", i), |_| ())
}
}))
// Delimiter are simple lines between items,
// and cannot be selected.
.delimiter()
.with(|tree| {
for i in 1..10 {
@ -36,18 +46,21 @@ fn main() {
s.add_layer(Dialog::info("Help message!"))
})
.leaf("Online", |s| {
s.add_layer(Dialog::info("Google it \
yourself!\nKids, \
these days..."))
let text = "Google it yourself!\n\
Kids, these days...";
s.add_layer(Dialog::info(text))
}))
.leaf("About",
|s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
// When `autohide` is on (default), the menu only appears when it is active.
// Turning it off will leave the menu always visible.
// siv.set_autohide_menu(false);
siv.add_global_callback(Key::Esc, |s| s.select_menubar());
siv.add_layer(Dialog::around(TextView::new("Hit <Esc> to show the menu!")));
siv.add_layer(Dialog::text("Hit <Esc> to show the menu!"));
siv.run();
}

View File

@ -204,7 +204,7 @@ impl Cursive {
/// Sets the menubar autohide_menubar feature.
///
/// * When enabled, the menu is only visible when selected.
/// * When enabled (default), the menu is only visible when selected.
/// * When disabled, the menu is always visible and reserves the top row.
pub fn set_autohide_menu(&mut self, autohide: bool) {
self.menubar.autohide = autohide;