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