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