Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn display_none() {
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 { flex_grow: 1f32, ..Default::default() }).unwrap();
7 let node1 = taffy
8 .new_leaf(taffy::style::Style { display: taffy::style::Display::None, flex_grow: 1f32, ..Default::default() })
9 .unwrap();
10 let node = taffy
11 .new_with_children(
12 taffy::style::Style {
13 size: taffy::geometry::Size {
14 width: taffy::style::Dimension::Length(100f32),
15 height: taffy::style::Dimension::Length(100f32),
16 },
17 ..Default::default()
18 },
19 &[node0, node1],
20 )
21 .unwrap();
22 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
23 println!("\nComputed tree:");
24 taffy.print_tree(node);
25 println!();
26 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
27 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
28 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
29 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
30 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
31 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
32 #[cfg(feature = "content_size")]
33 assert_eq!(
34 layout.scroll_width(),
35 0f32,
36 "scroll_width of node {:?}. Expected {}. Actual {}",
37 node,
38 0f32,
39 layout.scroll_width()
40 );
41 #[cfg(feature = "content_size")]
42 assert_eq!(
43 layout.scroll_height(),
44 0f32,
45 "scroll_height of node {:?}. Expected {}. Actual {}",
46 node,
47 0f32,
48 layout.scroll_height()
49 );
50 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
51 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
52 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
53 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 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 node0,
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 node0,
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(node1).unwrap();
76 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
77 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
78 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
79 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 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 node1,
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 node1,
95 0f32,
96 layout.scroll_height()
97 );
98}