tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definitions

⎇ 39cd0fcbbda7cd38cc6316e7339b1f3aed29e99f tests/generated/flex_basis_and_main_dimen_set_when_flexing.rs Rust · 56 lines · 2.3 KB History Who touched what raw

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

1#[test]
2fn flex_basis_and_main_dimen_set_when_flexing() {
3    let mut taffy = taffy::Taffy::new();
4    let node0 = taffy
5        .new_with_children(
6            taffy::style::FlexboxLayout {
7                flex_grow: 1f32,
8                flex_basis: taffy::style::Dimension::Points(10f32),
9                size: taffy::geometry::Size {
10                    width: taffy::style::Dimension::Points(50f32),
11                    height: taffy::style::Dimension::Points(50f32),
12                    ..Default::default()
13                },
14                ..Default::default()
15            },
16            &[],
17        )
18        .unwrap();
19    let node1 = taffy
20        .new_with_children(
21            taffy::style::FlexboxLayout {
22                flex_grow: 1f32,
23                flex_basis: taffy::style::Dimension::Points(10f32),
24                size: taffy::geometry::Size {
25                    width: taffy::style::Dimension::Points(0f32),
26                    height: taffy::style::Dimension::Points(50f32),
27                    ..Default::default()
28                },
29                ..Default::default()
30            },
31            &[],
32        )
33        .unwrap();
34    let node = taffy
35        .new_with_children(
36            taffy::style::FlexboxLayout {
37                size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), ..Default::default() },
38                ..Default::default()
39            },
40            &[node0, node1],
41        )
42        .unwrap();
43    taffy.compute_layout(node, taffy::geometry::Size::undefined()).unwrap();
44    assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
45    assert_eq!(taffy.layout(node).unwrap().size.height, 50f32);
46    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
47    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
48    assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32);
49    assert_eq!(taffy.layout(node0).unwrap().size.height, 50f32);
50    assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32);
51    assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
52    assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32);
53    assert_eq!(taffy.layout(node1).unwrap().size.height, 50f32);
54    assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32);
55    assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32);
56}