⎇ ae87fd0283feff32a5ceffe4c77394ff6ca88d39
tests/generated/grid_align_items_baseline_multiline_row_and_column.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Grid: baseline alignment support (#344)
1#[test]
2fn grid_align_items_baseline_multiline_row_and_column() {
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 display: taffy::style::Display::Grid,
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Points(50f32),
12 height: taffy::style::Dimension::Points(50f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node10 = taffy
18 .new_leaf(taffy::style::Style {
19 display: taffy::style::Display::Grid,
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::Points(50f32),
22 height: taffy::style::Dimension::Points(10f32),
23 },
24 ..Default::default()
25 })
26 .unwrap();
27 let node1 = taffy
28 .new_with_children(
29 taffy::style::Style {
30 display: taffy::style::Display::Grid,
31 size: taffy::geometry::Size {
32 width: taffy::style::Dimension::Points(50f32),
33 height: taffy::style::Dimension::Points(50f32),
34 },
35 ..Default::default()
36 },
37 &[node10],
38 )
39 .unwrap();
40 let node20 = taffy
41 .new_leaf(taffy::style::Style {
42 display: taffy::style::Display::Grid,
43 size: taffy::geometry::Size {
44 width: taffy::style::Dimension::Points(50f32),
45 height: taffy::style::Dimension::Points(10f32),
46 },
47 ..Default::default()
48 })
49 .unwrap();
50 let node2 = taffy
51 .new_with_children(
52 taffy::style::Style {
53 display: taffy::style::Display::Grid,
54 size: taffy::geometry::Size {
55 width: taffy::style::Dimension::Points(50f32),
56 height: taffy::style::Dimension::Points(20f32),
57 },
58 ..Default::default()
59 },
60 &[node20],
61 )
62 .unwrap();
63 let node3 = taffy
64 .new_leaf(taffy::style::Style {
65 display: taffy::style::Display::Grid,
66 size: taffy::geometry::Size {
67 width: taffy::style::Dimension::Points(50f32),
68 height: taffy::style::Dimension::Points(20f32),
69 },
70 ..Default::default()
71 })
72 .unwrap();
73 let node = taffy
74 .new_with_children(
75 taffy::style::Style {
76 display: taffy::style::Display::Grid,
77 align_items: Some(taffy::style::AlignItems::Baseline),
78 grid_template_columns: vec![auto(), auto()],
79 size: taffy::geometry::Size {
80 width: taffy::style::Dimension::Points(100f32),
81 height: taffy::style::Dimension::Points(100f32),
82 },
83 ..Default::default()
84 },
85 &[node0, node1, node2, node3],
86 )
87 .unwrap();
88 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
89 println!("\nComputed tree:");
90 taffy::debug::print_tree(&taffy, node);
91 println!();
92 let Layout { size, location, .. } = taffy.layout(node).unwrap();
93 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
94 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
95 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
96 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
97 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
98 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
99 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
100 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
101 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
102 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
103 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
104 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height);
105 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.x);
106 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
107 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
108 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
109 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
110 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
111 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
112 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
113 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
114 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, size.height);
115 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
116 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, location.y);
117 let Layout { size, location, .. } = taffy.layout(node20).unwrap();
118 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node20.data(), 50f32, size.width);
119 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node20.data(), 10f32, size.height);
120 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node20.data(), 0f32, location.x);
121 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20.data(), 0f32, location.y);
122 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
123 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width);
124 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 20f32, size.height);
125 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, location.x);
126 assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 90f32, location.y);
127}