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