Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn flex_basis_flex_shrink_column() {
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 { flex_basis: taffy::style::Dimension::Length(100f32), ..Default::default() })
8 .unwrap();
9 let node1 = taffy
10 .new_leaf(taffy::style::Style { flex_basis: taffy::style::Dimension::Length(50f32), ..Default::default() })
11 .unwrap();
12 let node = taffy
13 .new_with_children(
14 taffy::style::Style {
15 flex_direction: taffy::style::FlexDirection::Column,
16 size: taffy::geometry::Size {
17 width: taffy::style::Dimension::Length(100f32),
18 height: taffy::style::Dimension::Length(100f32),
19 },
20 ..Default::default()
21 },
22 &[node0, node1],
23 )
24 .unwrap();
25 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
26 println!("\nComputed tree:");
27 taffy.print_tree(node);
28 println!();
29 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
30 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
31 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
32 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
33 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35 #[cfg(feature = "content_size")]
36 assert_eq!(
37 layout.scroll_width(),
38 0f32,
39 "scroll_width of node {:?}. Expected {}. Actual {}",
40 node,
41 0f32,
42 layout.scroll_width()
43 );
44 #[cfg(feature = "content_size")]
45 assert_eq!(
46 layout.scroll_height(),
47 0f32,
48 "scroll_height of node {:?}. Expected {}. Actual {}",
49 node,
50 0f32,
51 layout.scroll_height()
52 );
53 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
54 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
55 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
56 assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, size.height);
57 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
59 #[cfg(feature = "content_size")]
60 assert_eq!(
61 layout.scroll_width(),
62 0f32,
63 "scroll_width of node {:?}. Expected {}. Actual {}",
64 node0,
65 0f32,
66 layout.scroll_width()
67 );
68 #[cfg(feature = "content_size")]
69 assert_eq!(
70 layout.scroll_height(),
71 0f32,
72 "scroll_height of node {:?}. Expected {}. Actual {}",
73 node0,
74 0f32,
75 layout.scroll_height()
76 );
77 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
78 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
79 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
80 assert_eq!(size.height, 33f32, "height of node {:?}. Expected {}. Actual {}", node1, 33f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
82 assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node1, 67f32, location.y);
83 #[cfg(feature = "content_size")]
84 assert_eq!(
85 layout.scroll_width(),
86 0f32,
87 "scroll_width of node {:?}. Expected {}. Actual {}",
88 node1,
89 0f32,
90 layout.scroll_width()
91 );
92 #[cfg(feature = "content_size")]
93 assert_eq!(
94 layout.scroll_height(),
95 0f32,
96 "scroll_height of node {:?}. Expected {}. Actual {}",
97 node1,
98 0f32,
99 layout.scroll_height()
100 );
101}