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