Unify method names on Menubar and MenuTree

This commit is contained in:
Alexandre Bury 2017-01-23 16:51:48 -08:00
parent 24b342ced8
commit 0977daa12d
3 changed files with 12 additions and 10 deletions

View File

@ -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()

View File

@ -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

View File

@ -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;