Skip to content

Commit

Permalink
pretty print tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed Dec 23, 2017
1 parent dfd8e85 commit 43c94d3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
34 changes: 29 additions & 5 deletions components/gfx_traits/print_tree.rs
Expand Up @@ -22,20 +22,29 @@ impl PrintTree {
}
}

/// Descend one level in the tree with the given title.
pub fn new_level(&mut self, title: String) {
/// Descend one level in the tree with the given title string.
pub fn new_level(&mut self, queued_title: String) {
self.flush_queued_item("\u{251C}\u{2500}");

self.print_level_prefix();
println!("\u{251C}\u{2500} {}", title);

let items: Vec<&str> = queued_title.split("\n").collect();
println!("\u{251C}\u{2500} {}", items[0]);
for i in 1..items.len() {
self.print_level_child_indentation();
print!("{}", items[i]);
if i < items.len() {
print!("\n");
}
}

self.level = self.level + 1;
}

/// Ascend one level in the tree.
pub fn end_level(&mut self) {
self.flush_queued_item("\u{2514}\u{2500}");
self.level = self.level - 1;
self.level -= 1;
}

/// Add an item to the current level in the tree.
Expand All @@ -50,10 +59,25 @@ impl PrintTree {
}
}

fn print_level_child_indentation(&self) {
for _ in 0..(self.level + 1) {
print!("\u{2502} ");
}
print!("{}", " ".repeat(7));
}

fn flush_queued_item(&mut self, prefix: &str) {
if let Some(queued_item) = self.queued_item.take() {
self.print_level_prefix();
println!("{} {}", prefix, queued_item);
let items: Vec<&str> = queued_item.split("\n").collect();
println!("{} {}", prefix, items[0]);
for i in 1..items.len() {
self.print_level_child_indentation();
print!("{}", items[i]);
if i < items.len() {
print!("\n");
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/layout/block.rs
Expand Up @@ -2191,7 +2191,7 @@ impl Flow for BlockFlow {
}

fn print_extra_flow_children(&self, print_tree: &mut PrintTree) {
print_tree.add_item(format!("↑↑ Fragment for block: {:?}", self.fragment));
print_tree.add_item(format!("↑↑ Fragment for block:{:?}", self.fragment));
}
}

Expand Down
13 changes: 8 additions & 5 deletions components/layout/flow.rs
Expand Up @@ -925,26 +925,29 @@ impl fmt::Debug for BaseFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let child_count = self.parallel.children_count.load(Ordering::SeqCst);
let child_count_string = if child_count > 0 {
format!(" children={}", child_count)
format!("\nchildren={}", child_count)
} else {
"".to_owned()
};

let absolute_descendants_string = if self.abs_descendants.len() > 0 {
format!(" abs-descendents={}", self.abs_descendants.len())
format!("\nabs-descendents={}", self.abs_descendants.len())
} else {
"".to_owned()
};

let damage_string = if self.restyle_damage != RestyleDamage::empty() {
format!(" damage={:?}", self.restyle_damage)
format!("\ndamage={:?}", self.restyle_damage)
} else {
"".to_owned()
};

write!(f,
"sc={:?} pos={:?}, {}{} floatspec-in={:?}, floatspec-out={:?}, \
overflow={:?}{}{}{}",
"\nsc={:?}\
\npos={:?}{}{}\
\nfloatspec-in={:?}\
\nfloatspec-out={:?}\
\noverflow={:?}{}{}{}",
self.stacking_context_id,
self.position,
if self.flags.contains(FlowFlags::FLOATS_LEFT) { "FL" } else { "" },
Expand Down
8 changes: 4 additions & 4 deletions components/layout/fragment.rs
Expand Up @@ -2958,24 +2958,24 @@ impl Fragment {
impl fmt::Debug for Fragment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let border_padding_string = if !self.border_padding.is_zero() {
format!(" border_padding={:?}", self.border_padding)
format!("\nborder_padding={:?}", self.border_padding)
} else {
"".to_owned()
};

let margin_string = if !self.margin.is_zero() {
format!(" margin={:?}", self.margin)
format!("\nmargin={:?}", self.margin)
} else {
"".to_owned()
};

let damage_string = if self.restyle_damage != RestyleDamage::empty() {
format!(" damage={:?}", self.restyle_damage)
format!("\ndamage={:?}", self.restyle_damage)
} else {
"".to_owned()
};

write!(f, "{}({}) [{:?}] border_box={:?}{}{}{}",
write!(f, "\n{}({}) [{:?}]\nborder_box={:?}{}{}{}",
self.specific.get_type(),
self.debug_id,
self.specific,
Expand Down

0 comments on commit 43c94d3

Please sign in to comment.