From 0977daa12d9998fc13cb053cf882cbfa21b5040b Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 23 Jan 2017 16:51:48 -0800 Subject: [PATCH] Unify method names on Menubar and MenuTree --- examples/menubar.rs | 6 +++--- src/views/menubar.rs | 10 +++++----- src/views/stack_view.rs | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/menubar.rs b/examples/menubar.rs index c7f2361..8c1c384 100644 --- a/examples/menubar.rs +++ b/examples/menubar.rs @@ -18,7 +18,7 @@ fn main() { // The menubar is a list of (label, menu tree) pairs. siv.menubar() // We add a new "File" tree - .add("File", + .add_subtree("File", MenuTree::new() // Trees are made of leaves, with are directly actionable... .leaf("New", move |s| { @@ -26,7 +26,7 @@ fn main() { // in the list of "Recent" items. let i = counter.fetch_add(1, Ordering::Relaxed); let filename = format!("New {}", i); - s.menubar().find("File").unwrap() + s.menubar().find_subtree("File").unwrap() .find_subtree("Recent").unwrap() .insert_leaf(0, filename, |_| ()); @@ -53,7 +53,7 @@ fn main() { }) .delimiter() .leaf("Quit", |s| s.quit())) - .add("Help", + .add_subtree("Help", MenuTree::new() .subtree("Help", MenuTree::new() diff --git a/src/views/menubar.rs b/src/views/menubar.rs index b9e7cfa..39ff6d2 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -76,13 +76,13 @@ impl Menubar { /// /// The item will use the given title, and on selection, will open a /// popup-menu with the given menu tree. - pub fn add(&mut self, title: &str, menu: MenuTree) -> &mut Self { + pub fn add_subtree(&mut self, title: &str, menu: MenuTree) -> &mut Self { let i = self.menus.len(); - self.insert(i, title, menu) + self.insert_subtree(i, title, menu) } /// Insert a new item at the given position. - pub fn insert(&mut self, i: usize, title: &str, menu: MenuTree) + pub fn insert_subtree(&mut self, i: usize, title: &str, menu: MenuTree) -> &mut Self { self.menus.insert(i, (title.to_string(), Rc::new(menu))); self @@ -102,14 +102,14 @@ impl Menubar { /// Returns the item at the given position. /// /// Returns `None` if `i > self.len()` - pub fn get(&mut self, i: usize) -> Option<&mut MenuTree> { + pub fn get_subtree(&mut self, i: usize) -> Option<&mut MenuTree> { self.menus .get_mut(i) .map(|&mut (_, ref mut tree)| Rc::make_mut(tree)) } /// Looks for an item with the given label. - pub fn find(&mut self, label: &str) -> Option<&mut MenuTree> { + pub fn find_subtree(&mut self, label: &str) -> Option<&mut MenuTree> { // Look for the menu with the correct label, // then call Rc::make_mut on the tree. // If another Rc on this tree existed, this will clone diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index e2b93d0..e2c21a7 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -112,8 +112,10 @@ impl View for StackView { layer.size = size; layer.view.layout(layer.size); - // We do it here instead of when adding a new layer because...? - // (TODO: try to make it during layer addition) + // We need to call `layout()` on the view before giving it focus + // for the first time. Otherwise it will not be properly set up. + // Ex: examples/lorem.rs: the text view takes focus because it's + // scrolling, but it only knows that after a call to `layout()`. if layer.virgin { layer.view.take_focus(Direction::none()); layer.virgin = false;