Skip to content
Snippets Groups Projects
Unverified Commit 4410cd98 authored by John's avatar John Committed by GitHub
Browse files

Revert "kayak_core: Improve `Tree` methods"

parent 5801520d
No related branches found
No related tags found
No related merge requests found
......@@ -591,9 +591,9 @@ impl KayakContext {
#[allow(dead_code)]
fn get_all_parents(&self, current: Index, parents: &mut Vec<Index>) {
if let Some(parent) = self.widget_manager.tree.get_parent(current) {
parents.push(parent);
self.get_all_parents(parent, parents);
if let Some(parent) = self.widget_manager.tree.parents.get(&current) {
parents.push(*parent);
self.get_all_parents(*parent, parents);
}
}
......
......@@ -253,7 +253,7 @@ impl EventDispatcher {
let mut event_stream = Vec::<Event>::new();
let mut states: HashMap<EventType, EventState> = HashMap::new();
let root = if let Some(root) = widget_manager.node_tree.root() {
let root = if let Some(root) = widget_manager.node_tree.root_node {
root
} else {
return event_stream;
......@@ -351,7 +351,7 @@ impl EventDispatcher {
// --- Push Children to Stack --- //
if enter_children {
if let Some(children) = widget_manager.node_tree.get_children(current) {
if let Some(children) = widget_manager.node_tree.children.get(&current) {
for child in children {
stack.push((*child, depth + 1));
}
......
......@@ -36,7 +36,7 @@ impl FocusTree {
}
}
if self.tree.root().is_none() {
if self.tree.root_node.is_none() {
// Set root node
self.tree.add(index, None);
self.focus(index);
......@@ -49,7 +49,7 @@ impl FocusTree {
self.blur();
}
if self.tree.root() == Some(index) {
if self.tree.root_node == Some(index) {
self.tree.remove(index);
} else {
self.tree.remove_and_reparent(index);
......@@ -76,7 +76,7 @@ impl FocusTree {
///
/// This returns focus to the root node
pub fn blur(&mut self) {
self.current_focus = self.tree.root();
self.current_focus = self.tree.root_node;
}
/// Get the currently focused index
......@@ -120,7 +120,7 @@ impl FocusTree {
}
// Default to root node to begin the cycle again
self.tree.root()
self.tree.root_node
}
/// Peek the previous focusable index without actually changing focus
......@@ -149,7 +149,7 @@ impl FocusTree {
return Some(next);
}
self.tree.root()
self.tree.root_node
}
pub fn tree(&self) -> &Tree {
......
This diff is collapsed.
......@@ -63,7 +63,7 @@ impl WidgetManager {
pub fn dirty(&mut self, force: bool) {
// Force tree to re-render from root.
if let Ok(mut dirty_nodes) = self.dirty_nodes.lock() {
dirty_nodes.insert(self.tree.root().unwrap());
dirty_nodes.insert(self.tree.root_node.unwrap());
if force {
for (node_index, _) in self.current_widgets.iter() {
......@@ -81,7 +81,7 @@ impl WidgetManager {
parent: Option<Index>,
) -> (bool, Index) {
let widget_id = if let Some(parent) = parent.clone() {
if let Some(parent_children) = self.tree.get_children(parent) {
if let Some(parent_children) = self.tree.children.get_mut(&parent) {
parent_children.get(index).cloned()
} else {
None
......@@ -203,10 +203,10 @@ impl WidgetManager {
// 2. Unresolved widget prop styles
// 3. Unresolved default styles
let parent_styles =
if let Some(parent_widget_id) = self.tree.get_parent(dirty_node_index) {
if let Some(parent) = self.nodes[parent_widget_id].as_ref() {
if let Some(parent_widget_id) = self.tree.parents.get(&dirty_node_index) {
if let Some(parent) = self.nodes[*parent_widget_id].as_ref() {
parent.resolved_styles.clone()
} else if let Some(parent) = self.current_widgets[parent_widget_id].as_ref() {
} else if let Some(parent) = self.current_widgets[*parent_widget_id].as_ref() {
if let Some(styles) = parent.get_props().get_styles() {
styles
} else {
......@@ -220,8 +220,9 @@ impl WidgetManager {
};
// Get parent Z
let parent_z = if let Some(parent_widget_id) = self.tree.get_parent(dirty_node_index) {
if let Some(parent) = &self.nodes[parent_widget_id] {
let parent_z = if let Some(parent_widget_id) = self.tree.parents.get(&dirty_node_index)
{
if let Some(parent) = &self.nodes[*parent_widget_id] {
parent.z
} else {
-1.0
......@@ -251,9 +252,10 @@ impl WidgetManager {
let children = self
.tree
.get_children(dirty_node_index)
.unwrap_or_default()
.to_vec();
.children
.get(&dirty_node_index)
.cloned()
.unwrap_or(vec![]);
let mut node = NodeBuilder::empty()
.with_id(dirty_node_index)
......@@ -364,8 +366,8 @@ impl WidgetManager {
prev_clip = new_prev_clip.clone();
if let Some(children) = node_tree.get_children(current_node) {
for child in children {
if node_tree.children.contains_key(&current_node) {
for child in node_tree.children.get(&current_node).unwrap() {
main_z_index += 1.0;
render_primitives.extend(Self::recurse_node_tree_to_build_primitives(
node_tree,
......@@ -404,7 +406,7 @@ impl WidgetManager {
}
pub fn build_render_primitives(&self) -> Vec<RenderPrimitive> {
if self.node_tree.root().is_none() {
if self.node_tree.root_node.is_none() {
return vec![];
}
......@@ -412,16 +414,20 @@ impl WidgetManager {
&self.node_tree,
&self.layout_cache,
&self.nodes,
self.node_tree.root().unwrap(),
self.node_tree.root_node.unwrap(),
0.0,
RenderPrimitive::Empty,
)
}
fn build_nodes_tree(&mut self) -> Tree {
let mut tree = Tree::default();
let (root_node_id, _) = self.current_widgets.iter().next().unwrap();
let mut tree = Tree::new(root_node_id);
tree.add_children(self.get_valid_node_children(root_node_id), root_node_id);
tree.root_node = Some(root_node_id);
tree.children.insert(
tree.root_node.unwrap(),
self.get_valid_node_children(tree.root_node.unwrap()),
);
let old_focus = self.focus_tree.current();
self.focus_tree.clear();
......@@ -432,10 +438,12 @@ impl WidgetManager {
if let Some(widget_styles) = widget_styles {
// Only add widgets who have renderable nodes.
if widget_styles.render_command.resolve() != RenderCommand::Empty {
let valid_parent = self.get_valid_parent(widget_id);
tree.insert_direct(widget_id, valid_parent);
let valid_children = self.get_valid_node_children(widget_id);
tree.insert_children_direct(valid_children, widget_id);
tree.children.insert(widget_id, valid_children);
let valid_parent = self.get_valid_parent(widget_id);
if let Some(valid_parent) = valid_parent {
tree.parents.insert(widget_id, valid_parent);
}
}
}
......@@ -451,14 +459,12 @@ impl WidgetManager {
}
}
tree.recalculate_depths(None);
tree
}
pub fn get_valid_node_children(&self, node_id: Index) -> Vec<Index> {
let mut children = Vec::new();
if let Some(node_children) = self.tree.get_children(node_id) {
if let Some(node_children) = self.tree.children.get(&node_id) {
for child_id in node_children {
if let Some(child_widget) = &self.current_widgets[*child_id] {
if let Some(child_styles) = child_widget.get_props().get_styles() {
......@@ -478,13 +484,13 @@ impl WidgetManager {
}
pub fn get_valid_parent(&self, node_id: Index) -> Option<Index> {
if let Some(parent_id) = self.tree.get_parent(node_id) {
if let Some(parent_widget) = &self.nodes[parent_id] {
if let Some(parent_id) = self.tree.parents.get(&node_id) {
if let Some(parent_widget) = &self.nodes[*parent_id] {
if parent_widget.resolved_styles.render_command.resolve() != RenderCommand::Empty {
return Some(parent_id);
return Some(*parent_id);
}
}
return self.get_valid_parent(parent_id);
return self.get_valid_parent(*parent_id);
}
// assert!(node_id.into_raw_parts().0 == 0);
None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment