@@ -1,24 +1,24 @@
1−use crate::View;
2−use slotmap::{DefaultKey as Key, HopSlotMap};
1+use crate::{View, ViewId};
2+use slotmap::HopSlotMap;
33use tui::layout::Rect;
44
55// the dimensions are recomputed on windo resize/tree change.
66//
77pub struct Tree {
8− root: Key,
8+ root: ViewId,
99 // (container, index inside the container)
10− pub focus: Key,
10+ pub focus: ViewId,
1111 // fullscreen: bool,
1212 area: Rect,
1313
14− nodes: HopSlotMap<Key, Node>,
14+ nodes: HopSlotMap<ViewId, Node>,
1515
1616 // used for traversals
17− stack: Vec<(Key, Rect)>,
17+ stack: Vec<(ViewId, Rect)>,
1818}
1919
2020pub struct Node {
21− parent: Key,
21+ parent: ViewId,
2222 content: Content,
2323}
2424
@@ -30,14 +30,14 @@ pub enum Content {
3030impl Node {
3131 pub fn container() -> Self {
3232 Node {
33− parent: Key::default(),
33+ parent: ViewId::default(),
3434 content: Content::Container(Box::new(Container::new())),
3535 }
3636 }
3737
3838 pub fn view(view: View) -> Self {
3939 Node {
40− parent: Key::default(),
40+ parent: ViewId::default(),
4141 content: Content::View(Box::new(view)),
4242 }
4343 }
@@ -53,7 +53,7 @@ pub enum Layout {
5353
5454pub struct Container {
5555 layout: Layout,
56− children: Vec<Key>,
56+ children: Vec<ViewId>,
5757 area: Rect,
5858}
5959
@@ -77,7 +77,7 @@ impl Tree {
7777 pub fn new(area: Rect) -> Self {
7878 let root = Node::container();
7979
80− let mut nodes = HopSlotMap::new();
80+ let mut nodes = HopSlotMap::with_key();
8181 let root = nodes.insert(root);
8282
8383 // root is it's own parent
@@ -93,7 +93,7 @@ impl Tree {
9393 }
9494 }
9595
96− pub fn insert(&mut self, view: View) -> Key {
96+ pub fn insert(&mut self, view: View) -> ViewId {
9797 let focus = self.focus;
9898 let parent = self.nodes[focus].parent;
9999 let mut node = Node::view(view);
@@ -131,7 +131,7 @@ impl Tree {
131131 node
132132 }
133133
134− pub fn remove(&mut self, index: Key) {
134+ pub fn remove(&mut self, index: ViewId) {
135135 let mut stack = Vec::new();
136136
137137 if self.focus == index {
@@ -188,7 +188,7 @@ impl Tree {
188188 })
189189 }
190190
191− pub fn get(&self, index: Key) -> &View {
191+ pub fn get(&self, index: ViewId) -> &View {
192192 match &self.nodes[index] {
193193 Node {
194194 content: Content::View(view),
@@ -198,7 +198,7 @@ impl Tree {
198198 }
199199 }
200200
201− pub fn get_mut(&mut self, index: Key) -> &mut View {
201+ pub fn get_mut(&mut self, index: ViewId) -> &mut View {
202202 match &mut self.nodes[index] {
203203 Node {
204204 content: Content::View(view),
@@ -355,7 +355,7 @@ impl Tree {
355355
356356pub struct Traverse<'a> {
357357 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
359359}
360360
361361impl<'a> Traverse<'a> {
@@ -368,7 +368,7 @@ impl<'a> Traverse<'a> {
368368}
369369
370370impl<'a> Iterator for Traverse<'a> {
371− type Item = (Key, &'a View);
371+ type Item = (ViewId, &'a View);
372372
373373 fn next(&mut self) -> Option<Self::Item> {
374374 loop {