feat: Updated the Ratatui Tree Widget to allow the tree to story any data type that implements Into<Text>, so that users can also easily fetch data from within the tree based on what's selected for non-text data types.

This commit is contained in:
2024-11-14 15:38:37 -07:00
parent 735f111866
commit 3e23a73f6b
8 changed files with 78 additions and 84 deletions
+8 -8
View File
@@ -14,7 +14,7 @@ use crate::tree_item::TreeItem;
/// # Example
///
/// ```
/// # use tui_tree_widget::TreeState;
/// # use managarr_tree_widget::TreeState;
/// type Identifier = usize;
///
/// let mut state = TreeState::<Identifier>::default();
@@ -67,7 +67,7 @@ where
items: &'a [TreeItem<Identifier, T>],
) -> Vec<Flattened<'a, Identifier, T>>
where
T: for<'b> Into<Text<'b>> + Clone,
T: for<'b> Into<Text<'b>> + Clone + Default,
{
flatten(&self.opened, items, &[])
}
@@ -79,7 +79,7 @@ where
/// Clear the selection by passing an empty identifier vector:
///
/// ```rust
/// # use tui_tree_widget::TreeState;
/// # use managarr_tree_widget::TreeState;
/// # let mut state = TreeState::<usize>::default();
/// state.select(Vec::new());
/// ```
@@ -195,13 +195,13 @@ where
/// # Example
///
/// ```
/// # use tui_tree_widget::TreeState;
/// # use managarr_tree_widget::TreeState;
/// # type Identifier = usize;
/// # let mut state = TreeState::<Identifier>::default();
/// // Move the selection one down
/// state.select_visible_relative(|current| {
/// state.select_relative(|current| {
/// // When nothing is currently selected, select index 0
/// // Otherwise select current + 1 (without panicing)
/// // Otherwise select current + 1 (without panicking)
/// current.map_or(0, |current| current.saturating_add(1))
/// });
/// ```
@@ -230,13 +230,13 @@ where
/// # Example
///
/// ```
/// # use tui_tree_widget::TreeState;
/// # use managarr_tree_widget::TreeState;
/// # type Identifier = usize;
/// # let mut state = TreeState::<Identifier>::default();
/// // Move the selection one down
/// state.select_relative(|current| {
/// // When nothing is currently selected, select index 0
/// // Otherwise select current + 1 (without panicing)
/// // Otherwise select current + 1 (without panicking)
/// current.map_or(0, |current| current.saturating_add(1))
/// });
/// ```