feat: toggle with identifier

BREAKING CHANGE: toggle now requires identifier
This commit is contained in:
EdJoPaTo
2022-08-31 14:21:53 +02:00
parent 0a631330e3
commit 63a5fa06f9
2 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -60,6 +60,6 @@ impl<'a> StatefulTree<'a> {
} }
pub fn toggle(&mut self) { pub fn toggle(&mut self) {
self.state.toggle(); self.state.toggle_selected();
} }
} }
+10 -4
View File
@@ -68,14 +68,20 @@ impl TreeState {
/// Toggles a tree node. /// Toggles a tree node.
/// If the node is in opened then it calls `close()`. Otherwise it calls `open()`. /// If the node is in opened then it calls `close()`. Otherwise it calls `open()`.
pub fn toggle(&mut self) { pub fn toggle(&mut self, identifier: TreeIdentifierVec) {
if self.opened.contains(&self.selected()) { if self.opened.contains(&identifier) {
self.close(&self.selected()); self.close(&identifier);
} else { } else {
self.open(self.selected()); self.open(identifier);
} }
} }
/// Toggles the currently selected tree node.
/// See also [`toggle`](TreeState::toggle)
pub fn toggle_selected(&mut self) {
self.toggle(self.selected());
}
pub fn close_all(&mut self) { pub fn close_all(&mut self) {
self.opened.clear(); self.opened.clear();
} }