feat: Adding toggle (#8)

* feat: Adding toggle

* Update src/lib.rs

Return unneded

Co-authored-by: EdJoPaTo <github@edjopato.de>

Co-authored-by: EdJoPaTo <github@edjopato.de>
This commit is contained in:
Nicholas Roller
2022-02-06 15:13:29 -05:00
committed by GitHub
parent c50c0329d9
commit 7ff37c6227
3 changed files with 17 additions and 0 deletions
+10
View File
@@ -58,6 +58,16 @@ impl TreeState {
self.opened.remove(identifier)
}
/// Toggles a tree node.
/// If the node is in opened then it calls `close()`. Otherwise it calls `open()`.
pub fn toggle(&mut self) {
if self.opened.contains(&self.selected()) {
self.close(&self.selected());
} else {
self.open(self.selected());
}
}
pub fn close_all(&mut self) {
self.opened.clear();
}