⎇ 163284a65cd48cdf6c6b96b9216284cb1fefacd3
tests/generated/grid_min_content_flex_row.rs
Historia
Quién tocó qué
crudo
Fix sizing of flexbox nodes under a min-content constraint (#291)
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(known_dimensions, available_space, TEXT)
13 }),
14 )
15 .unwrap();
16 let node01 = taffy
17 .new_leaf_with_measure(
18 taffy::style::Style { ..Default::default() },
19 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
20 const TEXT: &str = "HH\u{200b}HH";
21 super::measure_standard_text(known_dimensions, available_space, TEXT)
22 }),
23 )
24 .unwrap();
25 let node02 = taffy
26 .new_leaf_with_measure(
27 taffy::style::Style { ..Default::default() },
28 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
29 const TEXT: &str = "HH\u{200b}HH";
30 super::measure_standard_text(known_dimensions, available_space, TEXT)
31 }),
32 )
33 .unwrap();
34 let node0 = taffy
35 .new_with_children(
36 taffy::style::Style { display: taffy::style::Display::Flex, ..Default::default() },
37 &[node00, node01, node02],
38 )
39 .unwrap();
40 let node = taffy
41 .new_with_children(
42 taffy::style::Style {
43 display: taffy::style::Display::Grid,
44 grid_template_rows: vec![points(40f32)],
45 grid_template_columns: vec![min_content()],
46 ..Default::default()
47 },
48 &[node0],
49 )
50 .unwrap();
51 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52 println!("\nComputed tree:");
53 taffy::debug::print_tree(&taffy, node);
54 println!();
55 let Layout { size, location, .. } = taffy.layout(node).unwrap();
56 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.width);
57 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
60 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.width);
62 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
64 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
65 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
66 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
67 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 40f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
70 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
71 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, size.width);
72 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 40f32, size.height);
73 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
75 let Layout { size, location, .. } = taffy.layout(node02).unwrap();
76 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
77 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 40f32, size.height);
78 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 40f32, location.x);
79 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.y);
80}