use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NodeId(pub u64);
impl fmt::Display for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone)]
pub struct ItemNode<T> {
pub id: NodeId,
pub data: T,
pub children: Vec<ItemNode<T>>,
}
impl<T> ItemNode<T> {
pub fn leaf(id: NodeId, data: T) -> Self {
Self {
id,
data,
children: Vec::new(),
}
}
pub fn branch(id: NodeId, data: T, children: Vec<ItemNode<T>>) -> Self {
Self { id, data, children }
}
}
#[derive(Debug, Clone)]
pub(crate) struct InternalItem<T> {
pub(crate) id: NodeId,
pub(crate) data: T,
pub(crate) depth: u32,
pub(crate) children_ids: Vec<NodeId>,
pub(crate) parent_id: Option<NodeId>,
pub(crate) is_expanded: bool,
pub(crate) is_selected: bool,
}
impl<T> InternalItem<T> {
pub(crate) fn has_children(&self) -> bool {
!self.children_ids.is_empty()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct VisibleItem {
pub id: NodeId,
pub label: String,
pub depth: u32,
pub is_expanded: bool,
pub has_children: bool,
pub is_selected: bool,
pub is_active: bool,
}