gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

⎇ 0.5.x tests/generated/flex/margin_auto_left_and_right.rs Rust · 118 siq'ikuna · 4.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn margin_auto_left_and_right() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(50f32),
11            },
12            margin: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentageAuto::Auto,
14                right: taffy::style::LengthPercentageAuto::Auto,
15                top: zero(),
16                bottom: zero(),
17            },
18            ..Default::default()
19        })
20        .unwrap();
21    let node1 = taffy
22        .new_leaf(taffy::style::Style {
23            size: taffy::geometry::Size {
24                width: taffy::style::Dimension::Length(50f32),
25                height: taffy::style::Dimension::Length(50f32),
26            },
27            ..Default::default()
28        })
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                size: taffy::geometry::Size {
34                    width: taffy::style::Dimension::Length(200f32),
35                    height: taffy::style::Dimension::Length(200f32),
36                },
37                ..Default::default()
38            },
39            &[node0, node1],
40        )
41        .unwrap();
42    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
43    println!("\nComputed tree:");
44    taffy.print_tree(node);
45    println!();
46    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
47    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
48    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
49    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
52    #[cfg(feature = "content_size")]
53    assert_eq!(
54        layout.scroll_width(),
55        0f32,
56        "scroll_width of node {:?}. Expected {}. Actual {}",
57        node,
58        0f32,
59        layout.scroll_width()
60    );
61    #[cfg(feature = "content_size")]
62    assert_eq!(
63        layout.scroll_height(),
64        0f32,
65        "scroll_height of node {:?}. Expected {}. Actual {}",
66        node,
67        0f32,
68        layout.scroll_height()
69    );
70    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
71    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
72    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
73    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
74    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node0, 50f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
76    #[cfg(feature = "content_size")]
77    assert_eq!(
78        layout.scroll_width(),
79        0f32,
80        "scroll_width of node {:?}. Expected {}. Actual {}",
81        node0,
82        0f32,
83        layout.scroll_width()
84    );
85    #[cfg(feature = "content_size")]
86    assert_eq!(
87        layout.scroll_height(),
88        0f32,
89        "scroll_height of node {:?}. Expected {}. Actual {}",
90        node0,
91        0f32,
92        layout.scroll_height()
93    );
94    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
95    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
96    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
97    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
98    assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node1, 150f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
100    #[cfg(feature = "content_size")]
101    assert_eq!(
102        layout.scroll_width(),
103        0f32,
104        "scroll_width of node {:?}. Expected {}. Actual {}",
105        node1,
106        0f32,
107        layout.scroll_width()
108    );
109    #[cfg(feature = "content_size")]
110    assert_eq!(
111        layout.scroll_height(),
112        0f32,
113        "scroll_height of node {:?}. Expected {}. Actual {}",
114        node1,
115        0f32,
116        layout.scroll_height()
117    );
118}