mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
Add comments to menubar example
This commit is contained in:
parent
44dbd5826e
commit
90c9d51a6c
@ -1,25 +1,35 @@
|
|||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::menu::MenuTree;
|
|
||||||
use cursive::views::{Dialog, TextView};
|
|
||||||
use cursive::event::Key;
|
use cursive::event::Key;
|
||||||
|
use cursive::menu::MenuTree;
|
||||||
use cursive::traits::*;
|
use cursive::traits::*;
|
||||||
|
use cursive::views::Dialog;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let mut siv = Cursive::new();
|
let mut siv = Cursive::new();
|
||||||
|
|
||||||
|
// The menubar is a list of (label, menu tree) pairs.
|
||||||
siv.menubar()
|
siv.menubar()
|
||||||
|
// We add a new "File" tree
|
||||||
.add("File",
|
.add("File",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
|
// Trees are made of leaves, with are directly actionable...
|
||||||
.leaf("New", |s| s.add_layer(Dialog::info("New file!")))
|
.leaf("New", |s| s.add_layer(Dialog::info("New file!")))
|
||||||
|
// ... and of sub-trees, which open up when selected.
|
||||||
.subtree("Recent",
|
.subtree("Recent",
|
||||||
|
// The `.with()` method can help when running loops
|
||||||
|
// within builder patterns.
|
||||||
MenuTree::new().with(|tree| {
|
MenuTree::new().with(|tree| {
|
||||||
for i in 1..100 {
|
for i in 1..100 {
|
||||||
|
// We don't actually do anything here,
|
||||||
|
// but you could!
|
||||||
tree.add_leaf(&format!("Item {}", i), |_| ())
|
tree.add_leaf(&format!("Item {}", i), |_| ())
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
// Delimiter are simple lines between items,
|
||||||
|
// and cannot be selected.
|
||||||
.delimiter()
|
.delimiter()
|
||||||
.with(|tree| {
|
.with(|tree| {
|
||||||
for i in 1..10 {
|
for i in 1..10 {
|
||||||
@ -36,18 +46,21 @@ fn main() {
|
|||||||
s.add_layer(Dialog::info("Help message!"))
|
s.add_layer(Dialog::info("Help message!"))
|
||||||
})
|
})
|
||||||
.leaf("Online", |s| {
|
.leaf("Online", |s| {
|
||||||
s.add_layer(Dialog::info("Google it \
|
let text = "Google it yourself!\n\
|
||||||
yourself!\nKids, \
|
Kids, these days...";
|
||||||
these days..."))
|
s.add_layer(Dialog::info(text))
|
||||||
}))
|
}))
|
||||||
.leaf("About",
|
.leaf("About",
|
||||||
|s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
|
|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.set_autohide_menu(false);
|
||||||
|
|
||||||
siv.add_global_callback(Key::Esc, |s| s.select_menubar());
|
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();
|
siv.run();
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ impl Cursive {
|
|||||||
|
|
||||||
/// Sets the menubar autohide_menubar feature.
|
/// 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.
|
/// * When disabled, the menu is always visible and reserves the top row.
|
||||||
pub fn set_autohide_menu(&mut self, autohide: bool) {
|
pub fn set_autohide_menu(&mut self, autohide: bool) {
|
||||||
self.menubar.autohide = autohide;
|
self.menubar.autohide = autohide;
|
||||||
|
Loading…
Reference in New Issue
Block a user