Add menubar example

Not working yet, but at least it shows how the API should be used.
This commit is contained in:
Alexandre Bury 2016-06-28 01:10:48 -07:00
parent d02c30ae9f
commit d0d4380d5a
2 changed files with 26 additions and 2 deletions

24
examples/menubar.rs Normal file
View File

@ -0,0 +1,24 @@
extern crate cursive;
use cursive::Cursive;
use cursive::view::Dialog;
use cursive::event::Key;
fn main() {
let mut siv = Cursive::new();
siv.menu()
.new_subtree("File")
.leaf("New", |s| s.add_layer(Dialog::info("New file!")))
.leaf("Quit", |s| s.quit());
siv.menu()
.new_subtree("Help")
.leaf("Help", |s| s.add_layer(Dialog::info("Help message!")))
.leaf("About", |s| s.add_layer(Dialog::info("Cursive v0.0.0")));
siv.add_global_callback(Key::F(10), |s| s.select_menu());
siv.run();
}

View File

@ -48,10 +48,10 @@ impl MenuTree {
self self
} }
pub fn new_subtree(&mut self, title: &str) -> &mut Box<MenuTree> { pub fn new_subtree(&mut self, title: &str) -> &mut MenuTree {
self.add_subtree(title, MenuTree::new()); self.add_subtree(title, MenuTree::new());
match *self.children.last_mut().unwrap() { match *self.children.last_mut().unwrap() {
MenuItem::Subtree(_, ref mut tree) => tree, MenuItem::Subtree(_, ref mut tree) => &mut *tree,
_ => panic!("??"), _ => panic!("??"),
} }
} }