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