tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91822 Definitions

⎇ bce89b1006f36ce35abfaf1f1c2b3dd95f3dffd3 tests/generated/absolute_layout_child_order.rs Rust · 76 lines · 3.1 KB History Who touched what raw

index: update tests to API changes 48c69198a · msiglreith ·

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