gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ 0.1.x tests/generated/absolute_layout_child_order.rs Rust · 76 líneas · 3.0 KB Historia Quién tocó qué crudo

Rename sprawl to taffy (#134) 8936790d6 · Alice Cecile ·

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