1use parley::layout::PositionedLayoutItem;
2
3use crate::BaseDocument;
4
5impl BaseDocument {
6 pub fn print_taffy_tree(&self) {
7 taffy::print_tree(self, taffy::NodeId::from(0usize));
8 }
9
10 pub fn debug_log_node(&self, node_id: usize) {
11 let node = &self.nodes[node_id];
12
13 #[cfg(feature = "tracing")]
14 {
15 tracing::info!("Layout: {:?}", &node.final_layout);
16 tracing::info!("Style: {:?}", &node.style);
17 }
18
19 println!("\nNode {} {}", node.id, node.node_debug_str());
20
21 println!("Attrs:");
22
23 for attr in node.attrs().into_iter().flatten() {
24 println!(" {}: {}", attr.name.local, attr.value);
25 }
26
27 if node.flags.is_inline_root() {
28 let inline_layout = &node
29 .data
30 .downcast_element()
31 .unwrap()
32 .inline_layout_data
33 .as_ref()
34 .unwrap();
35
36 println!(
37 "Size: {}x{}",
38 inline_layout.layout.width(),
39 inline_layout.layout.height()
40 );
41 println!("Text content: {:?}", inline_layout.text);
42 println!("Inline Boxes:");
43 for ibox in inline_layout.layout.inline_boxes() {
44 print!("(id: {}) ", ibox.id);
45 }
46 println!();
47 println!("Lines:");
48 for (i, line) in inline_layout.layout.lines().enumerate() {
49 let metrics = line.metrics();
50 let x = metrics.inline_min_coord;
51 let y = metrics.block_min_coord;
52 let w = metrics.inline_max_coord - metrics.inline_min_coord;
53 let h = metrics.block_max_coord - metrics.block_min_coord;
54 println!("Line {i}: x:{x} y:{y} width:{w} height:{h}");
55 for item in line.items() {
56 print!(" ");
57 match item {
58 PositionedLayoutItem::GlyphRun(run) => {
59 print!(
60 "RUN (x: {}, w: {}) ",
61 run.offset().round(),
62 run.run().advance()
63 )
64 }
65 PositionedLayoutItem::InlineBox(ibox) => print!(
66 "BOX {:?} (id: {} x: {} y: {} w: {}, h: {})",
67 ibox.kind,
68 ibox.id,
69 ibox.x.round(),
70 ibox.y.round(),
71 ibox.width.round(),
72 ibox.height.round()
73 ),
74 }
75 println!();
76 }
77 }
78 }
79
80 let layout = &node.final_layout;
81 println!("Layout:");
82 println!(
83 " x: {x} y: {y} w: {width} h: {height} content_w: {content_width} content_h: {content_height}",
84 x = layout.location.x,
85 y = layout.location.y,
86 width = layout.size.width,
87 height = layout.size.height,
88 content_width = layout.content_size.width,
89 content_height = layout.content_size.height,
90 );
91 println!(
92 " border: l:{l} r:{r} t:{t} b:{b}",
93 l = layout.border.left,
94 r = layout.border.right,
95 t = layout.border.top,
96 b = layout.border.bottom,
97 );
98 println!(
99 " padding: l:{l} r:{r} t:{t} b:{b}",
100 l = layout.padding.left,
101 r = layout.padding.right,
102 t = layout.padding.top,
103 b = layout.padding.bottom,
104 );
105 println!(
106 " margin: l:{l} r:{r} t:{t} b:{b}",
107 l = layout.margin.left,
108 r = layout.margin.right,
109 t = layout.margin.top,
110 b = layout.margin.bottom,
111 );
112 println!("Parent: {:?}", node.parent);
113
114 let children: Vec<_> = node
115 .children
116 .iter()
117 .map(|id| &self.nodes[*id])
118 .map(|node| (node.id, node.order(), node.node_debug_str()))
119 .collect();
120 println!("Children: {children:?}");
121
122 println!("Layout Parent: {:?}", node.layout_parent.get());
123
124 let layout_children: Option<Vec<_>> = node.layout_children.borrow().as_ref().map(|lc| {
125 lc.iter()
126 .map(|id| &self.nodes[*id])
127 .map(|node| (node.id, node.order(), node.node_debug_str()))
128 .collect()
129 });
130 if let Some(layout_children) = layout_children {
131 println!("Layout Children: {layout_children:?}");
132 }
133
134 let paint_children: Option<Vec<_>> = node.paint_children.borrow().as_ref().map(|lc| {
135 lc.iter()
136 .map(|id| &self.nodes[*id])
137 .map(|node| (node.id, node.order(), node.node_debug_str()))
138 .collect()
139 });
140 if let Some(paint_children) = paint_children {
141 println!("Paint Children: {paint_children:?}");
142 }
143 }
145}