Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

Commit

Permalink
add_child now listens to active bool properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Timidger committed Sep 11, 2016
1 parent 43fa75f commit aad8934
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/layout/core/graph_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::{Debug, Formatter};
use std::fmt::Result as FmtResult;

use petgraph::EdgeDirection;
use petgraph::graph::{Graph, NodeIndex};
use petgraph::graph::{Graph, NodeIndex, EdgeIndex};
use uuid::Uuid;

use rustwlc::WlcView;
Expand Down Expand Up @@ -164,17 +164,21 @@ impl InnerTree {
pub fn add_child(&mut self, parent_ix: NodeIndex, val: Container, active: bool) -> NodeIndex {
let id = val.get_id();
let child_ix = self.graph.add_node(val);
self.attach_child(parent_ix, child_ix);
let edge = self.attach_child(parent_ix, child_ix);
if active {
self.set_ancestor_paths_active(child_ix);
} else {
let mut weight = self.graph.edge_weight_mut(edge)
.expect("Could not get edge weight of parent/child");
weight.active = false;
}
self.id_map.insert(id, child_ix);
child_ix
}

/// Add an existing node (detached in the graph) to the tree.
/// Note that floating nodes shouldn't exist for too long.
pub fn attach_child(&mut self, parent_ix: NodeIndex, child_ix: NodeIndex) {
fn attach_child(&mut self, parent_ix: NodeIndex, child_ix: NodeIndex) -> EdgeIndex {
// Make sure the child doesn't have a parent
if cfg!(debug_assertions) && self.has_parent(child_ix) {
panic!("attach_child: child had a parent!")
Expand All @@ -191,8 +195,9 @@ impl InnerTree {
}
let (_ix, mut biggest_child) = self.largest_child(parent_ix);
*biggest_child += 1;
self.graph.update_edge(parent_ix, child_ix, biggest_child);
let result = self.graph.update_edge(parent_ix, child_ix, biggest_child);
self.normalize_edge_weights(parent_ix);
result
}

/// Finds the index of the container at the child index's parent,
Expand Down
2 changes: 1 addition & 1 deletion src/layout/core/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ pub mod tests {
let wkspc_2_container = tree.add_child(root_container_2_ix,
Container::new_container(fake_geometry.clone()), false);
let wkspc_2_sub_view_1 = tree.add_child(wkspc_2_container,
Container::new_view(fake_view_1.clone()), false);
Container::new_view(fake_view_1.clone()), true);
let wkspc_2_sub_view_2 = tree.add_child(wkspc_2_container,
Container::new_view(fake_view_1.clone()), false);
let mut layout_tree = LayoutTree {
Expand Down

0 comments on commit aad8934

Please sign in to comment.