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