mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 11:16:03 +00:00
Unify method names on Menubar and MenuTree
This commit is contained in:
parent
24b342ced8
commit
0977daa12d
@ -18,7 +18,7 @@ fn main() {
|
|||||||
// The menubar is a list of (label, menu tree) pairs.
|
// The menubar is a list of (label, menu tree) pairs.
|
||||||
siv.menubar()
|
siv.menubar()
|
||||||
// We add a new "File" tree
|
// We add a new "File" tree
|
||||||
.add("File",
|
.add_subtree("File",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
// Trees are made of leaves, with are directly actionable...
|
// Trees are made of leaves, with are directly actionable...
|
||||||
.leaf("New", move |s| {
|
.leaf("New", move |s| {
|
||||||
@ -26,7 +26,7 @@ fn main() {
|
|||||||
// in the list of "Recent" items.
|
// in the list of "Recent" items.
|
||||||
let i = counter.fetch_add(1, Ordering::Relaxed);
|
let i = counter.fetch_add(1, Ordering::Relaxed);
|
||||||
let filename = format!("New {}", i);
|
let filename = format!("New {}", i);
|
||||||
s.menubar().find("File").unwrap()
|
s.menubar().find_subtree("File").unwrap()
|
||||||
.find_subtree("Recent").unwrap()
|
.find_subtree("Recent").unwrap()
|
||||||
.insert_leaf(0, filename, |_| ());
|
.insert_leaf(0, filename, |_| ());
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.delimiter()
|
.delimiter()
|
||||||
.leaf("Quit", |s| s.quit()))
|
.leaf("Quit", |s| s.quit()))
|
||||||
.add("Help",
|
.add_subtree("Help",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
.subtree("Help",
|
.subtree("Help",
|
||||||
MenuTree::new()
|
MenuTree::new()
|
||||||
|
@ -76,13 +76,13 @@ impl Menubar {
|
|||||||
///
|
///
|
||||||
/// The item will use the given title, and on selection, will open a
|
/// The item will use the given title, and on selection, will open a
|
||||||
/// popup-menu with the given menu tree.
|
/// 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();
|
let i = self.menus.len();
|
||||||
self.insert(i, title, menu)
|
self.insert_subtree(i, title, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a new item at the given position.
|
/// 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 {
|
-> &mut Self {
|
||||||
self.menus.insert(i, (title.to_string(), Rc::new(menu)));
|
self.menus.insert(i, (title.to_string(), Rc::new(menu)));
|
||||||
self
|
self
|
||||||
@ -102,14 +102,14 @@ impl Menubar {
|
|||||||
/// Returns the item at the given position.
|
/// Returns the item at the given position.
|
||||||
///
|
///
|
||||||
/// Returns `None` if `i > self.len()`
|
/// 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
|
self.menus
|
||||||
.get_mut(i)
|
.get_mut(i)
|
||||||
.map(|&mut (_, ref mut tree)| Rc::make_mut(tree))
|
.map(|&mut (_, ref mut tree)| Rc::make_mut(tree))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Looks for an item with the given label.
|
/// 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,
|
// Look for the menu with the correct label,
|
||||||
// then call Rc::make_mut on the tree.
|
// then call Rc::make_mut on the tree.
|
||||||
// If another Rc on this tree existed, this will clone
|
// If another Rc on this tree existed, this will clone
|
||||||
|
@ -112,8 +112,10 @@ impl View for StackView {
|
|||||||
layer.size = size;
|
layer.size = size;
|
||||||
layer.view.layout(layer.size);
|
layer.view.layout(layer.size);
|
||||||
|
|
||||||
// We do it here instead of when adding a new layer because...?
|
// We need to call `layout()` on the view before giving it focus
|
||||||
// (TODO: try to make it during layer addition)
|
// 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 {
|
if layer.virgin {
|
||||||
layer.view.take_focus(Direction::none());
|
layer.view.take_focus(Direction::none());
|
||||||
layer.virgin = false;
|
layer.virgin = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user