Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_align_items_baseline_child_margin() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 display: taffy::style::Display::Grid,
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(50f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: taffy::style::LengthPercentageAuto::Length(5f32),
15 right: taffy::style::LengthPercentageAuto::Length(5f32),
16 top: taffy::style::LengthPercentageAuto::Length(5f32),
17 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node10 = taffy
23 .new_leaf(taffy::style::Style {
24 display: taffy::style::Display::Grid,
25 size: taffy::geometry::Size {
26 width: taffy::style::Dimension::Length(50f32),
27 height: taffy::style::Dimension::Length(10f32),
28 },
29 margin: taffy::geometry::Rect {
30 left: taffy::style::LengthPercentageAuto::Length(5f32),
31 right: taffy::style::LengthPercentageAuto::Length(5f32),
32 top: taffy::style::LengthPercentageAuto::Length(5f32),
33 bottom: taffy::style::LengthPercentageAuto::Length(5f32),
34 },
35 ..Default::default()
36 })
37 .unwrap();
38 let node1 = taffy
39 .new_with_children(
40 taffy::style::Style {
41 display: taffy::style::Display::Grid,
42 size: taffy::geometry::Size {
43 width: taffy::style::Dimension::Length(50f32),
44 height: taffy::style::Dimension::Length(20f32),
45 },
46 ..Default::default()
47 },
48 &[node10],
49 )
50 .unwrap();
51 let node = taffy
52 .new_with_children(
53 taffy::style::Style {
54 display: taffy::style::Display::Grid,
55 align_items: Some(taffy::style::AlignItems::Baseline),
56 size: taffy::geometry::Size {
57 width: taffy::style::Dimension::Length(100f32),
58 height: taffy::style::Dimension::Length(100f32),
59 },
60 ..Default::default()
61 },
62 &[node0, node1],
63 )
64 .unwrap();
65 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
66 println!("\nComputed tree:");
67 taffy.print_tree(node);
68 println!();
69 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
70 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
71 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
72 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
73 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
75 #[cfg(feature = "content_size")]
76 assert_eq!(
77 layout.scroll_width(),
78 0f32,
79 "scroll_width of node {:?}. Expected {}. Actual {}",
80 node,
81 0f32,
82 layout.scroll_width()
83 );
84 #[cfg(feature = "content_size")]
85 assert_eq!(
86 layout.scroll_height(),
87 0f32,
88 "scroll_height of node {:?}. Expected {}. Actual {}",
89 node,
90 0f32,
91 layout.scroll_height()
92 );
93 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
94 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
95 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
96 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
97 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
98 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
99 #[cfg(feature = "content_size")]
100 assert_eq!(
101 layout.scroll_width(),
102 0f32,
103 "scroll_width of node {:?}. Expected {}. Actual {}",
104 node0,
105 0f32,
106 layout.scroll_width()
107 );
108 #[cfg(feature = "content_size")]
109 assert_eq!(
110 layout.scroll_height(),
111 0f32,
112 "scroll_height of node {:?}. Expected {}. Actual {}",
113 node0,
114 0f32,
115 layout.scroll_height()
116 );
117 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
118 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
119 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
120 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
121 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
122 assert_eq!(location.y, 70f32, "y of node {:?}. Expected {}. Actual {}", node1, 70f32, location.y);
123 #[cfg(feature = "content_size")]
124 assert_eq!(
125 layout.scroll_width(),
126 5f32,
127 "scroll_width of node {:?}. Expected {}. Actual {}",
128 node1,
129 5f32,
130 layout.scroll_width()
131 );
132 #[cfg(feature = "content_size")]
133 assert_eq!(
134 layout.scroll_height(),
135 0f32,
136 "scroll_height of node {:?}. Expected {}. Actual {}",
137 node1,
138 0f32,
139 layout.scroll_height()
140 );
141 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
142 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
143 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
144 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
145 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
146 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
147 #[cfg(feature = "content_size")]
148 assert_eq!(
149 layout.scroll_width(),
150 0f32,
151 "scroll_width of node {:?}. Expected {}. Actual {}",
152 node10,
153 0f32,
154 layout.scroll_width()
155 );
156 #[cfg(feature = "content_size")]
157 assert_eq!(
158 layout.scroll_height(),
159 0f32,
160 "scroll_height of node {:?}. Expected {}. Actual {}",
161 node10,
162 0f32,
163 layout.scroll_height()
164 );
165}