feat: Changed the tree to accept any type that implements Into<Text> so I can use the tree to fully store structs in the TUI as well as listing them

This commit is contained in:
2024-11-13 13:06:15 -07:00
parent 6e66e3e398
commit 735f111866
5 changed files with 109 additions and 75 deletions
+7 -3
View File
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use ratatui::layout::{Position, Rect};
use ratatui::text::Text;
use crate::flatten::{flatten, Flattened};
use crate::tree_item::TreeItem;
@@ -61,10 +62,13 @@ where
/// Get a flat list of all currently viewable (including by scrolling) [`TreeItem`]s with this `TreeState`.
#[must_use]
pub fn flatten<'text>(
pub fn flatten<'a, T>(
&self,
items: &'text [TreeItem<'text, Identifier>],
) -> Vec<Flattened<'text, Identifier>> {
items: &'a [TreeItem<Identifier, T>],
) -> Vec<Flattened<'a, Identifier, T>>
where
T: for<'b> Into<Text<'b>> + Clone,
{
flatten(&self.opened, items, &[])
}