tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definitions

⎇ 39cd0fcbbda7cd38cc6316e7339b1f3aed29e99f tests/generated/percent_within_flex_grow.rs Rust · 75 lines · 3.0 KB History Who touched what raw

Rename `new_node` to `new_with_children` (#142) 5d00d8fb9 · Andreas Weibye ·

1#[test]
2fn percent_within_flex_grow() {
3    let mut taffy = taffy::Taffy::new();
4    let node0 = taffy
5        .new_with_children(
6            taffy::style::FlexboxLayout {
7                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), ..Default::default() },
8                ..Default::default()
9            },
10            &[],
11        )
12        .unwrap();
13    let node10 = taffy
14        .new_with_children(
15            taffy::style::FlexboxLayout {
16                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), ..Default::default() },
17                ..Default::default()
18            },
19            &[],
20        )
21        .unwrap();
22    let node1 = taffy
23        .new_with_children(
24            taffy::style::FlexboxLayout {
25                flex_direction: taffy::style::FlexDirection::Column,
26                flex_grow: 1f32,
27                ..Default::default()
28            },
29            &[node10],
30        )
31        .unwrap();
32    let node2 = taffy
33        .new_with_children(
34            taffy::style::FlexboxLayout {
35                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), ..Default::default() },
36                ..Default::default()
37            },
38            &[],
39        )
40        .unwrap();
41    let node = taffy
42        .new_with_children(
43            taffy::style::FlexboxLayout {
44                size: taffy::geometry::Size {
45                    width: taffy::style::Dimension::Points(350f32),
46                    height: taffy::style::Dimension::Points(100f32),
47                    ..Default::default()
48                },
49                ..Default::default()
50            },
51            &[node0, node1, node2],
52        )
53        .unwrap();
54    taffy.compute_layout(node, taffy::geometry::Size::undefined()).unwrap();
55    assert_eq!(taffy.layout(node).unwrap().size.width, 350f32);
56    assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
57    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
58    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
59    assert_eq!(taffy.layout(node0).unwrap().size.width, 100f32);
60    assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32);
61    assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32);
62    assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
63    assert_eq!(taffy.layout(node1).unwrap().size.width, 150f32);
64    assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32);
65    assert_eq!(taffy.layout(node1).unwrap().location.x, 100f32);
66    assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32);
67    assert_eq!(taffy.layout(node10).unwrap().size.width, 150f32);
68    assert_eq!(taffy.layout(node10).unwrap().size.height, 0f32);
69    assert_eq!(taffy.layout(node10).unwrap().location.x, 0f32);
70    assert_eq!(taffy.layout(node10).unwrap().location.y, 0f32);
71    assert_eq!(taffy.layout(node2).unwrap().size.width, 100f32);
72    assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32);
73    assert_eq!(taffy.layout(node2).unwrap().location.x, 250f32);
74    assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32);
75}