gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ 0.1.x tests/generated/margin_auto_left_and_right_column.rs Rust · 62 lines · 2.4 KB History Who touched what raw

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

1#[test]
2fn margin_auto_left_and_right_column() {
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(50f32),
9                    height: taffy::style::Dimension::Points(50f32),
10                    ..Default::default()
11                },
12                margin: taffy::geometry::Rect {
13                    start: taffy::style::Dimension::Auto,
14                    end: taffy::style::Dimension::Auto,
15                    ..Default::default()
16                },
17                ..Default::default()
18            },
19            &[],
20        )
21        .unwrap();
22    let node1 = taffy
23        .new_node(
24            taffy::style::Style {
25                size: taffy::geometry::Size {
26                    width: taffy::style::Dimension::Points(50f32),
27                    height: taffy::style::Dimension::Points(50f32),
28                    ..Default::default()
29                },
30                ..Default::default()
31            },
32            &[],
33        )
34        .unwrap();
35    let node = taffy
36        .new_node(
37            taffy::style::Style {
38                align_items: taffy::style::AlignItems::Center,
39                size: taffy::geometry::Size {
40                    width: taffy::style::Dimension::Points(200f32),
41                    height: taffy::style::Dimension::Points(200f32),
42                    ..Default::default()
43                },
44                ..Default::default()
45            },
46            &[node0, node1],
47        )
48        .unwrap();
49    taffy.compute_layout(node, taffy::geometry::Size::undefined()).unwrap();
50    assert_eq!(taffy.layout(node).unwrap().size.width, 200f32);
51    assert_eq!(taffy.layout(node).unwrap().size.height, 200f32);
52    assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
53    assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
54    assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32);
55    assert_eq!(taffy.layout(node0).unwrap().size.height, 50f32);
56    assert_eq!(taffy.layout(node0).unwrap().location.x, 50f32);
57    assert_eq!(taffy.layout(node0).unwrap().location.y, 75f32);
58    assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32);
59    assert_eq!(taffy.layout(node1).unwrap().size.height, 50f32);
60    assert_eq!(taffy.layout(node1).unwrap().location.x, 150f32);
61    assert_eq!(taffy.layout(node1).unwrap().location.y, 75f32);
62}