From 90c9d51a6c2088f3282c28c850bef9bf4cdaef26 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 9 Oct 2016 15:56:03 -0700 Subject: [PATCH] Add comments to menubar example --- examples/menubar.rs | 25 +++++++++++++++++++------ src/lib.rs | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/examples/menubar.rs b/examples/menubar.rs index 419f6be..dd9e3a7 100644 --- a/examples/menubar.rs +++ b/examples/menubar.rs @@ -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 to show the menu!"))); + siv.add_layer(Dialog::text("Hit to show the menu!")); siv.run(); } diff --git a/src/lib.rs b/src/lib.rs index 5cd310e..577c559 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;