⎇ 606643cc5fe557da55d348d5f6d38a8791caa24d
tests/generated/gridflex_kitchen_sink_minimise3.rs
History
Who touched what
raw
Grid: Fix sizing issues in complex cases (#355)
1#[test]
2fn gridflex_kitchen_sink_minimise3() {
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 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(20f32),
11 height: taffy::style::Dimension::Points(20f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node01 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
17 let node02 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
18 let node03 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
19 let node0 = taffy
20 .new_with_children(
21 taffy::style::Style {
22 display: taffy::style::Display::Grid,
23 grid_template_rows: vec![percent(0.3f32), percent(0.1f32)],
24 grid_template_columns: vec![auto(), percent(0.1f32)],
25 ..Default::default()
26 },
27 &[node00, node01, node02, node03],
28 )
29 .unwrap();
30 let node = taffy
31 .new_with_children(
32 taffy::style::Style {
33 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() },
34 ..Default::default()
35 },
36 &[node0],
37 )
38 .unwrap();
39 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
40 println!("\nComputed tree:");
41 taffy::debug::print_tree(&taffy, node);
42 println!();
43 let Layout { size, location, .. } = taffy.layout(node).unwrap();
44 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 50f32, size.width);
45 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 20f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
48 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
49 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
50 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
51 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
52 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
53 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
54 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.width);
55 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 20f32, size.height);
56 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
57 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
58 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
59 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 2f32, size.width);
60 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 6f32, size.height);
61 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 20f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y);
63 let Layout { size, location, .. } = taffy.layout(node02).unwrap();
64 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node02.data(), 20f32, size.width);
65 assert_eq!(size.height, 2f32, "height of node {:?}. Expected {}. Actual {}", node02.data(), 2f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node02.data(), 0f32, location.x);
67 assert_eq!(location.y, 6f32, "y of node {:?}. Expected {}. Actual {}", node02.data(), 6f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node03).unwrap();
69 assert_eq!(size.width, 2f32, "width of node {:?}. Expected {}. Actual {}", node03.data(), 2f32, size.width);
70 assert_eq!(size.height, 2f32, "height of node {:?}. Expected {}. Actual {}", node03.data(), 2f32, size.height);
71 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node03.data(), 20f32, location.x);
72 assert_eq!(location.y, 6f32, "y of node {:?}. Expected {}. Actual {}", node03.data(), 6f32, location.y);
73}