Skip to content

Commit

Permalink
feat: toggle with identifier
Browse files Browse the repository at this point in the history
BREAKING CHANGE: toggle now requires identifier
  • Loading branch information
EdJoPaTo committed Aug 31, 2022
1 parent 0a63133 commit 63a5fa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ impl<'a> StatefulTree<'a> {
}

pub fn toggle(&mut self) {
self.state.toggle();
self.state.toggle_selected();
}
}
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ impl TreeState {

/// 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());
pub fn toggle(&mut self, identifier: TreeIdentifierVec) {
if self.opened.contains(&identifier) {
self.close(&identifier);
} 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) {
self.opened.clear();
}
Expand Down

0 comments on commit 63a5fa0

Please sign in to comment.