Improve API (#3)
* Introduce TreeItem::{child, child_mut}() accessors
* Add docstrings for TreeState::{open, close}()
This commit is contained in:
Regular → Executable
+14
@@ -49,6 +49,9 @@ impl TreeState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Open a tree node.
|
||||||
|
/// Returns `true` if the node was closed and has been opened.
|
||||||
|
/// Returns `false` if the node was already open.
|
||||||
pub fn open(&mut self, identifier: TreeIdentifierVec) -> bool {
|
pub fn open(&mut self, identifier: TreeIdentifierVec) -> bool {
|
||||||
if identifier.is_empty() {
|
if identifier.is_empty() {
|
||||||
false
|
false
|
||||||
@@ -57,6 +60,9 @@ impl TreeState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close a tree node.
|
||||||
|
/// Returns `true` if the node was open and has been closed.
|
||||||
|
/// Returns `false` if the node was already closed.
|
||||||
pub fn close(&mut self, identifier: TreeIdentifier) -> bool {
|
pub fn close(&mut self, identifier: TreeIdentifier) -> bool {
|
||||||
self.opened.remove(identifier)
|
self.opened.remove(identifier)
|
||||||
}
|
}
|
||||||
@@ -105,6 +111,14 @@ impl<'a> TreeItem<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn child(&self, index: usize) -> Option<&Self> {
|
||||||
|
self.children.get(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn child_mut(&mut self, index: usize) -> Option<&mut Self> {
|
||||||
|
self.children.get_mut(index)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn height(&self) -> usize {
|
pub fn height(&self) -> usize {
|
||||||
self.text.height()
|
self.text.height()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user