Improve API (#3)

* Introduce TreeItem::{child, child_mut}() accessors
* Add docstrings for TreeState::{open, close}()
This commit is contained in:
Joey Ezechiëls
2021-05-01 14:18:37 +02:00
committed by GitHub
parent fef66b4b5b
commit 8c43147be8
Regular → Executable
+14
View File
@@ -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 {
if identifier.is_empty() {
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 {
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 {
self.text.height()
}