⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32
tests/generated/grid_absolute_layout_within_border_static.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Fixes for aspect ratio and min/max sizes (#317)
1#[test]
2fn grid_absolute_layout_within_border_static() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 position: taffy::style::Position::Absolute,
10 align_self: Some(taffy::style::AlignSelf::Start),
11 justify_self: Some(taffy::style::JustifySelf::Start),
12 size: taffy::geometry::Size {
13 width: taffy::style::Dimension::Points(50f32),
14 height: taffy::style::Dimension::Points(50f32),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node1 = taffy
20 .new_leaf(taffy::style::Style {
21 position: taffy::style::Position::Absolute,
22 align_self: Some(taffy::style::AlignSelf::End),
23 justify_self: Some(taffy::style::JustifySelf::End),
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::Points(50f32),
26 height: taffy::style::Dimension::Points(50f32),
27 },
28 ..Default::default()
29 })
30 .unwrap();
31 let node2 = taffy
32 .new_leaf(taffy::style::Style {
33 position: taffy::style::Position::Absolute,
34 align_self: Some(taffy::style::AlignSelf::Start),
35 justify_self: Some(taffy::style::JustifySelf::Start),
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::Points(50f32),
38 height: taffy::style::Dimension::Points(50f32),
39 },
40 margin: taffy::geometry::Rect {
41 left: taffy::style::LengthPercentageAuto::Points(10f32),
42 right: taffy::style::LengthPercentageAuto::Points(10f32),
43 top: taffy::style::LengthPercentageAuto::Points(10f32),
44 bottom: taffy::style::LengthPercentageAuto::Points(10f32),
45 },
46 ..Default::default()
47 })
48 .unwrap();
49 let node3 = taffy
50 .new_leaf(taffy::style::Style {
51 position: taffy::style::Position::Absolute,
52 align_self: Some(taffy::style::AlignSelf::End),
53 justify_self: Some(taffy::style::JustifySelf::End),
54 size: taffy::geometry::Size {
55 width: taffy::style::Dimension::Points(50f32),
56 height: taffy::style::Dimension::Points(50f32),
57 },
58 margin: taffy::geometry::Rect {
59 left: taffy::style::LengthPercentageAuto::Points(10f32),
60 right: taffy::style::LengthPercentageAuto::Points(10f32),
61 top: taffy::style::LengthPercentageAuto::Points(10f32),
62 bottom: taffy::style::LengthPercentageAuto::Points(10f32),
63 },
64 ..Default::default()
65 })
66 .unwrap();
67 let node = taffy
68 .new_with_children(
69 taffy::style::Style {
70 display: taffy::style::Display::Grid,
71 size: taffy::geometry::Size {
72 width: taffy::style::Dimension::Points(100f32),
73 height: taffy::style::Dimension::Points(100f32),
74 },
75 padding: taffy::geometry::Rect {
76 left: taffy::style::LengthPercentage::Points(10f32),
77 right: taffy::style::LengthPercentage::Points(10f32),
78 top: taffy::style::LengthPercentage::Points(10f32),
79 bottom: taffy::style::LengthPercentage::Points(10f32),
80 },
81 border: taffy::geometry::Rect {
82 left: taffy::style::LengthPercentage::Points(10f32),
83 right: taffy::style::LengthPercentage::Points(10f32),
84 top: taffy::style::LengthPercentage::Points(10f32),
85 bottom: taffy::style::LengthPercentage::Points(10f32),
86 },
87 ..Default::default()
88 },
89 &[node0, node1, node2, node3],
90 )
91 .unwrap();
92 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
93 println!("\nComputed tree:");
94 taffy::debug::print_tree(&taffy, node);
95 println!();
96 let Layout { size, location, .. } = taffy.layout(node).unwrap();
97 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
98 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
101 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
102 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
103 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
104 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x);
105 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.y);
106 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
107 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
108 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height);
109 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x);
110 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
111 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
112 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
113 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height);
114 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.x);
115 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.y);
116 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
117 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width);
118 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.height);
119 assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.x);
120 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.y);
121}