gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 230Rust 8TOML 3CSS 1315 Definitions

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/display_none_with_child.rs Rust · 85 lines · 4.4 KB History Who touched what raw

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

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