Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn gridflex_kitchen_sink_minimise() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node00 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
9 ..Default::default()
10 })
11 .unwrap();
12 let node01 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
13 let node0 = taffy
14 .new_with_children(
15 taffy::style::Style {
16 display: taffy::style::Display::Grid,
17 grid_template_rows: vec![length(20f32)],
18 grid_template_columns: vec![fr(1f32), fr(1f32)],
19 ..Default::default()
20 },
21 &[node00, node01],
22 )
23 .unwrap();
24 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
25 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
26 println!("\nComputed tree:");
27 taffy.print_tree(node);
28 println!();
29 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
30 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
31 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
32 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
33 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35 #[cfg(feature = "content_size")]
36 assert_eq!(
37 layout.scroll_width(),
38 0f32,
39 "scroll_width of node {:?}. Expected {}. Actual {}",
40 node,
41 0f32,
42 layout.scroll_width()
43 );
44 #[cfg(feature = "content_size")]
45 assert_eq!(
46 layout.scroll_height(),
47 0f32,
48 "scroll_height of node {:?}. Expected {}. Actual {}",
49 node,
50 0f32,
51 layout.scroll_height()
52 );
53 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
54 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
55 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
56 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
57 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
59 #[cfg(feature = "content_size")]
60 assert_eq!(
61 layout.scroll_width(),
62 0f32,
63 "scroll_width of node {:?}. Expected {}. Actual {}",
64 node0,
65 0f32,
66 layout.scroll_width()
67 );
68 #[cfg(feature = "content_size")]
69 assert_eq!(
70 layout.scroll_height(),
71 0f32,
72 "scroll_height of node {:?}. Expected {}. Actual {}",
73 node0,
74 0f32,
75 layout.scroll_height()
76 );
77 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
79 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
80 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
82 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
83 #[cfg(feature = "content_size")]
84 assert_eq!(
85 layout.scroll_width(),
86 0f32,
87 "scroll_width of node {:?}. Expected {}. Actual {}",
88 node00,
89 0f32,
90 layout.scroll_width()
91 );
92 #[cfg(feature = "content_size")]
93 assert_eq!(
94 layout.scroll_height(),
95 0f32,
96 "scroll_height of node {:?}. Expected {}. Actual {}",
97 node00,
98 0f32,
99 layout.scroll_height()
100 );
101 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
102 let layout @ Layout { size, location, .. } = taffy.layout(node01).unwrap();
103 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
104 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
105 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
106 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
107 #[cfg(feature = "content_size")]
108 assert_eq!(
109 layout.scroll_width(),
110 0f32,
111 "scroll_width of node {:?}. Expected {}. Actual {}",
112 node01,
113 0f32,
114 layout.scroll_width()
115 );
116 #[cfg(feature = "content_size")]
117 assert_eq!(
118 layout.scroll_height(),
119 0f32,
120 "scroll_height of node {:?}. Expected {}. Actual {}",
121 node01,
122 0f32,
123 layout.scroll_height()
124 );
125}