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