⎇ 0.3.x
tests/generated/grid_align_items_baseline_double_nested_child.rs
Historia
Quién tocó qué
crudo
Grid: baseline alignment support (#344)
1#[test]
2fn grid_align_items_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 display: taffy::style::Display::Grid,
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Points(50f32),
12 height: taffy::style::Dimension::Points(20f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node0 = taffy
18 .new_with_children(
19 taffy::style::Style {
20 display: taffy::style::Display::Grid,
21 size: taffy::geometry::Size {
22 width: taffy::style::Dimension::Points(50f32),
23 height: taffy::style::Dimension::Points(50f32),
24 },
25 ..Default::default()
26 },
27 &[node00],
28 )
29 .unwrap();
30 let node10 = taffy
31 .new_leaf(taffy::style::Style {
32 display: taffy::style::Display::Grid,
33 size: taffy::geometry::Size {
34 width: taffy::style::Dimension::Points(50f32),
35 height: taffy::style::Dimension::Points(15f32),
36 },
37 ..Default::default()
38 })
39 .unwrap();
40 let node1 = taffy
41 .new_with_children(
42 taffy::style::Style {
43 display: taffy::style::Display::Grid,
44 size: taffy::geometry::Size {
45 width: taffy::style::Dimension::Points(50f32),
46 height: taffy::style::Dimension::Points(20f32),
47 },
48 ..Default::default()
49 },
50 &[node10],
51 )
52 .unwrap();
53 let node = taffy
54 .new_with_children(
55 taffy::style::Style {
56 display: taffy::style::Display::Grid,
57 align_items: Some(taffy::style::AlignItems::Baseline),
58 size: taffy::geometry::Size {
59 width: taffy::style::Dimension::Points(100f32),
60 height: taffy::style::Dimension::Points(100f32),
61 },
62 ..Default::default()
63 },
64 &[node0, node1],
65 )
66 .unwrap();
67 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
68 println!("\nComputed tree:");
69 taffy::debug::print_tree(&taffy, node);
70 println!();
71 let Layout { size, location, .. } = taffy.layout(node).unwrap();
72 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
73 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
76 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
77 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
78 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
81 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
82 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 50f32, size.width);
83 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
84 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
85 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
86 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
87 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width);
88 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
90 assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 65f32, location.y);
91 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
92 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 50f32, size.width);
93 assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 15f32, size.height);
94 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
95 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
96}