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