1#[test]
2fn align_baseline_double_nested_child() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(50f32),
11 height: taffy::style::Dimension::Points(20f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node0 = taffy
17 .new_with_children(
18 taffy::style::Style {
19 size: taffy::geometry::Size {
20 width: taffy::style::Dimension::Points(50f32),
21 height: taffy::style::Dimension::Points(50f32),
22 },
23 ..Default::default()
24 },
25 &[node00],
26 )
27 .unwrap();
28 let node10 = taffy
29 .new_leaf(taffy::style::Style {
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::Points(50f32),
32 height: taffy::style::Dimension::Points(15f32),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node1 = taffy
38 .new_with_children(
39 taffy::style::Style {
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Points(50f32),
42 height: taffy::style::Dimension::Points(20f32),
43 },
44 ..Default::default()
45 },
46 &[node10],
47 )
48 .unwrap();
49 let node = taffy
50 .new_with_children(
51 taffy::style::Style {
52 align_items: Some(taffy::style::AlignItems::Baseline),
53 size: taffy::geometry::Size {
54 width: taffy::style::Dimension::Points(100f32),
55 height: taffy::style::Dimension::Points(100f32),
56 },
57 ..Default::default()
58 },
59 &[node0, node1],
60 )
61 .unwrap();
62 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
63 println!("\nComputed tree:");
64 taffy::debug::print_tree(&taffy, node);
65 println!();
66 let Layout { size, location, .. } = taffy.layout(node).unwrap();
67 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
68 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
69 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
70 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
71 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
72 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
73 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
76 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
77 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 50f32, size.width);
78 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
81 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
82 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
83 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
84 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.x);
85 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 5f32, location.y);
86 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
87 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
88 assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 15f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
90 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
91}