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