⎇ 0.4.x
tests/generated/grid/grid_percent_items_nested_with_margin.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_percent_items_nested_with_margin() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node00 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
9 margin: taffy::geometry::Rect {
10 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
11 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node0 = taffy
19 .new_with_children(
20 taffy::style::Style {
21 display: taffy::style::Display::Grid,
22 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
23 ..Default::default()
24 },
25 &[node00],
26 )
27 .unwrap();
28 let node = taffy
29 .new_with_children(
30 taffy::style::Style {
31 display: taffy::style::Display::Grid,
32 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
33 ..Default::default()
34 },
35 &[node0],
36 )
37 .unwrap();
38 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
39 println!("\nComputed tree:");
40 taffy.print_tree(node);
41 println!();
42 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
43 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
44 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
45 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48 #[cfg(feature = "content_size")]
49 assert_eq!(
50 layout.scroll_width(),
51 0f32,
52 "scroll_width of node {:?}. Expected {}. Actual {}",
53 node,
54 0f32,
55 layout.scroll_width()
56 );
57 #[cfg(feature = "content_size")]
58 assert_eq!(
59 layout.scroll_height(),
60 0f32,
61 "scroll_height of node {:?}. Expected {}. Actual {}",
62 node,
63 0f32,
64 layout.scroll_height()
65 );
66 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
67 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
68 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
69 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
70 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
71 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
72 #[cfg(feature = "content_size")]
73 assert_eq!(
74 layout.scroll_width(),
75 0f32,
76 "scroll_width of node {:?}. Expected {}. Actual {}",
77 node0,
78 0f32,
79 layout.scroll_width()
80 );
81 #[cfg(feature = "content_size")]
82 assert_eq!(
83 layout.scroll_height(),
84 0f32,
85 "scroll_height of node {:?}. Expected {}. Actual {}",
86 node0,
87 0f32,
88 layout.scroll_height()
89 );
90 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
91 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
92 assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node00, 45f32, size.width);
93 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
94 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
95 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
96 #[cfg(feature = "content_size")]
97 assert_eq!(
98 layout.scroll_width(),
99 0f32,
100 "scroll_width of node {:?}. Expected {}. Actual {}",
101 node00,
102 0f32,
103 layout.scroll_width()
104 );
105 #[cfg(feature = "content_size")]
106 assert_eq!(
107 layout.scroll_height(),
108 0f32,
109 "scroll_height of node {:?}. Expected {}. Actual {}",
110 node00,
111 0f32,
112 layout.scroll_height()
113 );
114}