⎇ 76722686b0999e997dbe9c280ff9ea8567e0e95c
tests/generated/gridflex_column_integration.rs
Historia
Quién tocó qué
crudo
Grid: Fix sizing issues in complex cases (#355)
1#[test]
2fn gridflex_column_integration() {
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_with_measure(
9 taffy::style::Style { ..Default::default() },
10 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
11 const TEXT: &str = "HH";
12 super::measure_standard_text(
13 known_dimensions,
14 available_space,
15 TEXT,
16 super::WritingMode::Horizontal,
17 None,
18 )
19 }),
20 )
21 .unwrap();
22 let node01 = taffy
23 .new_leaf_with_measure(
24 taffy::style::Style { ..Default::default() },
25 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
26 const TEXT: &str = "HH";
27 super::measure_standard_text(
28 known_dimensions,
29 available_space,
30 TEXT,
31 super::WritingMode::Horizontal,
32 None,
33 )
34 }),
35 )
36 .unwrap();
37 let node02 = taffy
38 .new_leaf_with_measure(
39 taffy::style::Style { ..Default::default() },
40 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
41 const TEXT: &str = "HH";
42 super::measure_standard_text(
43 known_dimensions,
44 available_space,
45 TEXT,
46 super::WritingMode::Horizontal,
47 None,
48 )
49 }),
50 )
51 .unwrap();
52 let node03 = taffy
53 .new_leaf_with_measure(
54 taffy::style::Style { ..Default::default() },
55 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
56 const TEXT: &str = "HH";
57 super::measure_standard_text(
58 known_dimensions,
59 available_space,
60 TEXT,
61 super::WritingMode::Horizontal,
62 None,
63 )
64 }),
65 )
66 .unwrap();
67 let node0 = taffy
68 .new_with_children(
69 taffy::style::Style {
70 display: taffy::style::Display::Grid,
71 grid_template_rows: vec![flex(1f32), flex(1f32)],
72 grid_template_columns: vec![flex(1f32), flex(1f32)],
73 ..Default::default()
74 },
75 &[node00, node01, node02, node03],
76 )
77 .unwrap();
78 let node = taffy
79 .new_with_children(
80 taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
81 &[node0],
82 )
83 .unwrap();
84 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
85 println!("\nComputed tree:");
86 taffy::debug::print_tree(&taffy, node);
87 println!();
88 let Layout { size, location, .. } = taffy.layout(node).unwrap();
89 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width);
90 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
91 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
92 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
93 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
94 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
95 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
96 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
97 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
98 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
99 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
100 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, size.height);
101 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
102 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
103 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
104 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
105 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 10f32, size.height);
106 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.x);
107 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
108 let Layout { size, location, .. } = taffy.layout(node02).unwrap();
109 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
110 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, size.height);
111 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.x);
112 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 10f32, location.y);
113 let Layout { size, location, .. } = taffy.layout(node03).unwrap();
114 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node03.data(), 20f32, size.width);
115 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, size.height);
116 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03.data(), 20f32, location.x);
117 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node03.data(), 10f32, location.y);
118}