1#[test]
2fn align_baseline_child_top2() {
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 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(50f32),
11 height: taffy::style::Dimension::Points(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node10 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Points(50f32),
20 height: taffy::style::Dimension::Points(10f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node1 = taffy
26 .new_with_children(
27 taffy::style::Style {
28 size: taffy::geometry::Size {
29 width: taffy::style::Dimension::Points(50f32),
30 height: taffy::style::Dimension::Points(20f32),
31 },
32 inset: taffy::geometry::Rect {
33 left: auto(),
34 right: auto(),
35 top: taffy::style::LengthPercentageAuto::Points(5f32),
36 bottom: auto(),
37 },
38 ..Default::default()
39 },
40 &[node10],
41 )
42 .unwrap();
43 let node = taffy
44 .new_with_children(
45 taffy::style::Style {
46 align_items: Some(taffy::style::AlignItems::Baseline),
47 size: taffy::geometry::Size {
48 width: taffy::style::Dimension::Points(100f32),
49 height: taffy::style::Dimension::Points(100f32),
50 },
51 ..Default::default()
52 },
53 &[node0, node1],
54 )
55 .unwrap();
56 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
57 println!("\nComputed tree:");
58 taffy::debug::print_tree(&taffy, node);
59 println!();
60 let Layout { size, location, .. } = taffy.layout(node).unwrap();
61 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
62 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
64 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
65 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
66 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
67 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
70 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
71 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
72 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
73 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, location.x);
74 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 45f32, location.y);
75 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
76 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
77 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 10f32, size.height);
78 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
79 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
80}