1#[test]
2fn display_none_with_child() {
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 flex_grow: 1f32,
10 flex_shrink: 1f32,
11 flex_basis: taffy::style::Dimension::Percent(0f32),
12 ..Default::default()
13 })
14 .unwrap();
15 let node10 = taffy
16 .new_leaf(taffy::style::Style {
17 flex_grow: 1f32,
18 flex_shrink: 1f32,
19 flex_basis: taffy::style::Dimension::Percent(0f32),
20 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), height: auto() },
21 ..Default::default()
22 })
23 .unwrap();
24 let node1 = taffy
25 .new_with_children(
26 taffy::style::Style {
27 display: taffy::style::Display::None,
28 flex_direction: taffy::style::FlexDirection::Column,
29 flex_grow: 1f32,
30 flex_shrink: 1f32,
31 flex_basis: taffy::style::Dimension::Percent(0f32),
32 ..Default::default()
33 },
34 &[node10],
35 )
36 .unwrap();
37 let node2 = taffy
38 .new_leaf(taffy::style::Style {
39 flex_grow: 1f32,
40 flex_shrink: 1f32,
41 flex_basis: taffy::style::Dimension::Percent(0f32),
42 ..Default::default()
43 })
44 .unwrap();
45 let node = taffy
46 .new_with_children(
47 taffy::style::Style {
48 size: taffy::geometry::Size {
49 width: taffy::style::Dimension::Points(100f32),
50 height: taffy::style::Dimension::Points(100f32),
51 },
52 ..Default::default()
53 },
54 &[node0, node1, node2],
55 )
56 .unwrap();
57 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
58 println!("\nComputed tree:");
59 taffy::debug::print_tree(&taffy, node);
60 println!();
61 let Layout { size, location, .. } = taffy.layout(node).unwrap();
62 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
63 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height);
64 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
65 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
66 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
67 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width);
68 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
69 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
70 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
71 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
72 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, size.width);
73 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, size.height);
74 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
75 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
76 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
77 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, size.width);
78 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y);
81 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
82 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width);
83 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 100f32, size.height);
84 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, location.x);
85 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
86}