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