⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32
tests/generated/grid_percent_items_nested_with_padding_margin.rs
Historia
Quién tocó qué
crudo
Grid: Rename Flex to Fraction (#350)
1#[test]
2fn grid_percent_items_nested_with_padding_margin() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node000 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
10 margin: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15 },
16 padding: taffy::geometry::Rect {
17 left: taffy::style::LengthPercentage::Points(3f32),
18 right: taffy::style::LengthPercentage::Points(3f32),
19 top: taffy::style::LengthPercentage::Points(3f32),
20 bottom: taffy::style::LengthPercentage::Points(3f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node00 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 display: taffy::style::Display::Grid,
29 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
30 margin: taffy::geometry::Rect {
31 left: taffy::style::LengthPercentageAuto::Points(5f32),
32 right: taffy::style::LengthPercentageAuto::Points(5f32),
33 top: taffy::style::LengthPercentageAuto::Points(5f32),
34 bottom: taffy::style::LengthPercentageAuto::Points(5f32),
35 },
36 padding: taffy::geometry::Rect {
37 left: taffy::style::LengthPercentage::Percent(0.03f32),
38 right: taffy::style::LengthPercentage::Percent(0.03f32),
39 top: taffy::style::LengthPercentage::Percent(0.03f32),
40 bottom: taffy::style::LengthPercentage::Percent(0.03f32),
41 },
42 ..Default::default()
43 },
44 &[node000],
45 )
46 .unwrap();
47 let node0 = taffy
48 .new_with_children(
49 taffy::style::Style {
50 display: taffy::style::Display::Grid,
51 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.6f32), height: auto() },
52 margin: taffy::geometry::Rect {
53 left: taffy::style::LengthPercentageAuto::Points(5f32),
54 right: taffy::style::LengthPercentageAuto::Points(5f32),
55 top: taffy::style::LengthPercentageAuto::Points(5f32),
56 bottom: taffy::style::LengthPercentageAuto::Points(5f32),
57 },
58 padding: taffy::geometry::Rect {
59 left: taffy::style::LengthPercentage::Points(3f32),
60 right: taffy::style::LengthPercentage::Points(3f32),
61 top: taffy::style::LengthPercentage::Points(3f32),
62 bottom: taffy::style::LengthPercentage::Points(3f32),
63 },
64 ..Default::default()
65 },
66 &[node00],
67 )
68 .unwrap();
69 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
70 let node = taffy
71 .new_with_children(
72 taffy::style::Style {
73 display: taffy::style::Display::Grid,
74 grid_template_rows: vec![fr(1f32), fr(4f32)],
75 size: taffy::geometry::Size {
76 width: taffy::style::Dimension::Points(200f32),
77 height: taffy::style::Dimension::Points(200f32),
78 },
79 ..Default::default()
80 },
81 &[node0, node1],
82 )
83 .unwrap();
84 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
85 println!("\nComputed tree:");
86 taffy::debug::print_tree(&taffy, node);
87 println!();
88 let Layout { size, location, .. } = taffy.layout(node).unwrap();
89 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
90 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
91 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
92 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
93 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
94 assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 190f32, size.width);
95 assert_eq!(size.height, 41f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 41f32, size.height);
96 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.x);
97 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.y);
98 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
99 assert_eq!(size.width, 92f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 92f32, size.width);
100 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 25f32, size.height);
101 assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 8f32, location.x);
102 assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 8f32, location.y);
103 let Layout { size, location, .. } = taffy.layout(node000).unwrap();
104 assert_eq!(size.width, 36f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 36f32, size.width);
105 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 6f32, size.height);
106 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, location.x);
107 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 10f32, location.y);
108 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
109 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 200f32, size.width);
110 assert_eq!(size.height, 149f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 149f32, size.height);
111 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
112 assert_eq!(location.y, 51f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 51f32, location.y);
113}