Skip to content

Commit

Permalink
Fix print_tree function when taffy_tree feature is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 1, 2023
1 parent b364aee commit b51edf1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/util/debug.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#![allow(dead_code)]

use crate::prelude::Measurable;
use crate::style;
use crate::tree::{NodeId, Taffy};
use crate::{style, LayoutTree};
use crate::tree::{NodeId};
use core::fmt::{Debug, Display, Write};
use std::sync::Mutex;

/// Prints a debug representation of the computed layout for a tree of nodes, starting with the passed root node.
pub fn print_tree<NodeContext>(tree: &Taffy<NodeContext>, root: NodeId) {
pub fn print_tree(tree: &impl LayoutTree, root: NodeId) {
println!("TREE");
print_node(tree, root, false, String::new());
}

fn print_node<NodeContext>(tree: &Taffy<NodeContext>, node: NodeId, has_sibling: bool, lines_string: String) {
let layout = &tree.layout(node).unwrap();
let style = &tree.style(node).unwrap();
let num_children = tree.child_count(node).unwrap();
fn print_node(tree: &impl LayoutTree, node: NodeId, has_sibling: bool, lines_string: String) {
let layout = &tree.layout(node);
let style = &tree.style(node);
let num_children = tree.child_count(node);

let display = match (num_children, style.display) {
(_, style::Display::None) => "NONE",
Expand Down Expand Up @@ -44,7 +43,7 @@ fn print_node<NodeContext>(tree: &Taffy<NodeContext>, node: NodeId, has_sibling:
let new_string = lines_string + bar;

// Recurse into children
for (index, child) in tree.children(node).unwrap().into_iter().enumerate() {
for (index, child) in tree.children(node).into_iter().enumerate() {
let has_sibling = index < num_children - 1;
print_node(tree, child, has_sibling, new_string.clone());
}
Expand Down

0 comments on commit b51edf1

Please sign in to comment.