⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32
tests/generated/grid_min_content_flex_row.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Fixes for aspect ratio and min/max sizes (#317)
1#[test]
2fn grid_min_content_flex_row() {
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\u{200b}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\u{200b}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\u{200b}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 node0 = taffy
53 .new_with_children(
54 taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() },
55 &[node00, node01, node02],
56 )
57 .unwrap();
58 let node = taffy
59 .new_with_children(
60 taffy::style::Style {
61 display: taffy::style::Display::Grid,
62 grid_template_rows: vec![points(40f32)],
63 grid_template_columns: vec![min_content()],
64 ..Default::default()
65 },
66 &[node0],
67 )
68 .unwrap();
69 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
70 println!("\nComputed tree:");
71 taffy::debug::print_tree(&taffy, node);
72 println!();
73 let Layout { size, location, .. } = taffy.layout(node).unwrap();
74 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.width);
75 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height);
76 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
77 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
78 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
79 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.width);
80 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
81 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
82 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
83 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
84 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
85 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 40f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
87 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
88 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
89 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
90 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 40f32, size.height);
91 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.x);
92 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
93 let Layout { size, location, .. } = taffy.layout(node02).unwrap();
94 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
95 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 40f32, size.height);
96 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 40f32, location.x);
97 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.y);
98}