@@ -1,24 +1,24 @@
1−use crate::View;
1+use crate::{View, ViewId};
2−use slotmap::{DefaultKey as Key, HopSlotMap};
2+use slotmap::HopSlotMap;
3use tui::layout::Rect;
3use tui::layout::Rect;
5// the dimensions are recomputed on windo resize/tree change.
5// the dimensions are recomputed on windo resize/tree change.
7pub struct Tree {
7pub struct Tree {
8− root: Key,
8+ root: ViewId,
9 // (container, index inside the container)
9 // (container, index inside the container)
10− pub focus: Key,
10+ pub focus: ViewId,
11 // fullscreen: bool,
11 // fullscreen: bool,
12 area: Rect,
12 area: Rect,
14− nodes: HopSlotMap<Key, Node>,
14+ nodes: HopSlotMap<ViewId, Node>,
16 // used for traversals
16 // used for traversals
17− stack: Vec<(Key, Rect)>,
17+ stack: Vec<(ViewId, Rect)>,
20pub struct Node {
20pub struct Node {
21− parent: Key,
21+ parent: ViewId,
22 content: Content,
22 content: Content,
@@ -30,14 +30,14 @@ pub enum Content {
30impl Node {
30impl Node {
31 pub fn container() -> Self {
31 pub fn container() -> Self {
33− parent: Key::default(),
33+ parent: ViewId::default(),
34 content: Content::Container(Box::new(Container::new())),
34 content: Content::Container(Box::new(Container::new())),
38 pub fn view(view: View) -> Self {
38 pub fn view(view: View) -> Self {
40− parent: Key::default(),
40+ parent: ViewId::default(),
41 content: Content::View(Box::new(view)),
41 content: Content::View(Box::new(view)),
@@ -53,7 +53,7 @@ pub enum Layout {
54pub struct Container {
54pub struct Container {
55 layout: Layout,
55 layout: Layout,
56− children: Vec<Key>,
56+ children: Vec<ViewId>,
57 area: Rect,
57 area: Rect,
@@ -77,7 +77,7 @@ impl Tree {
77 pub fn new(area: Rect) -> Self {
77 pub fn new(area: Rect) -> Self {
78 let root = Node::container();
78 let root = Node::container();
80− let mut nodes = HopSlotMap::new();
80+ let mut nodes = HopSlotMap::with_key();
81 let root = nodes.insert(root);
81 let root = nodes.insert(root);
83 // root is it's own parent
83 // root is it's own parent
@@ -93,7 +93,7 @@ impl Tree {
96− pub fn insert(&mut self, view: View) -> Key {
96+ pub fn insert(&mut self, view: View) -> ViewId {
97 let focus = self.focus;
97 let focus = self.focus;
98 let parent = self.nodes[focus].parent;
98 let parent = self.nodes[focus].parent;
99 let mut node = Node::view(view);
99 let mut node = Node::view(view);
@@ -131,7 +131,7 @@ impl Tree {
134− pub fn remove(&mut self, index: Key) {
134+ pub fn remove(&mut self, index: ViewId) {
135 let mut stack = Vec::new();
135 let mut stack = Vec::new();
137 if self.focus == index {
137 if self.focus == index {
@@ -188,7 +188,7 @@ impl Tree {
191− pub fn get(&self, index: Key) -> &View {
191+ pub fn get(&self, index: ViewId) -> &View {
192 match &self.nodes[index] {
192 match &self.nodes[index] {
194 content: Content::View(view),
194 content: Content::View(view),
@@ -198,7 +198,7 @@ impl Tree {
201− pub fn get_mut(&mut self, index: Key) -> &mut View {
201+ pub fn get_mut(&mut self, index: ViewId) -> &mut View {
202 match &mut self.nodes[index] {
202 match &mut self.nodes[index] {
204 content: Content::View(view),
204 content: Content::View(view),
@@ -355,7 +355,7 @@ impl Tree {
356pub struct Traverse<'a> {
356pub struct Traverse<'a> {
357 tree: &'a Tree,
357 tree: &'a Tree,
358− stack: Vec<Key>, // TODO: reuse the one we use on update
358+ stack: Vec<ViewId>, // TODO: reuse the one we use on update
361impl<'a> Traverse<'a> {
361impl<'a> Traverse<'a> {
@@ -368,7 +368,7 @@ impl<'a> Traverse<'a> {
370impl<'a> Iterator for Traverse<'a> {
370impl<'a> Iterator for Traverse<'a> {
371− type Item = (Key, &'a View);
371+ type Item = (ViewId, &'a View);
373 fn next(&mut self) -> Option<Self::Item> {
373 fn next(&mut self) -> Option<Self::Item> {