tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Definiciones

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/margin_auto_left_stretching_child.rs Rust · 134 líneas · 6.5 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn margin_auto_left_stretching_child__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_grow: 1f32,
10            flex_shrink: 1f32,
11            flex_basis: taffy::style::Dimension::from_percent(0f32),
12            margin: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentageAuto::AUTO,
14                right: zero(),
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::from_length(50f32),
25                height: taffy::style::Dimension::from_length(50f32),
26            },
27            ..Default::default()
28        })
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                align_items: Some(taffy::style::AlignItems::Center),
34                size: taffy::geometry::Size {
35                    width: taffy::style::Dimension::from_length(200f32),
36                    height: taffy::style::Dimension::from_length(200f32),
37                },
38                ..Default::default()
39            },
40            &[node0, node1],
41        )
42        .unwrap();
43    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
44    println!("\nComputed tree:");
45    taffy.print_tree(node);
46    println!();
47    let layout = taffy.layout(node).unwrap();
48    let Layout { size, location, .. } = layout;
49    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
50    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
51    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
53    let layout = taffy.layout(node0).unwrap();
54    let Layout { size, location, .. } = layout;
55    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node0, 150f32, size.width);
56    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
57    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
59    let layout = taffy.layout(node1).unwrap();
60    let Layout { size, location, .. } = layout;
61    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
62    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
63    assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node1, 150f32, location.x);
64    assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
65}
66
67#[test]
68#[allow(non_snake_case)]
69fn margin_auto_left_stretching_child__content_box() {
70    #[allow(unused_imports)]
71    use taffy::{prelude::*, Layout};
72    let mut taffy = crate::new_test_tree();
73    let node0 = taffy
74        .new_leaf(taffy::style::Style {
75            box_sizing: taffy::style::BoxSizing::ContentBox,
76            flex_grow: 1f32,
77            flex_shrink: 1f32,
78            flex_basis: taffy::style::Dimension::from_percent(0f32),
79            margin: taffy::geometry::Rect {
80                left: taffy::style::LengthPercentageAuto::AUTO,
81                right: zero(),
82                top: zero(),
83                bottom: zero(),
84            },
85            ..Default::default()
86        })
87        .unwrap();
88    let node1 = taffy
89        .new_leaf(taffy::style::Style {
90            box_sizing: taffy::style::BoxSizing::ContentBox,
91            size: taffy::geometry::Size {
92                width: taffy::style::Dimension::from_length(50f32),
93                height: taffy::style::Dimension::from_length(50f32),
94            },
95            ..Default::default()
96        })
97        .unwrap();
98    let node = taffy
99        .new_with_children(
100            taffy::style::Style {
101                box_sizing: taffy::style::BoxSizing::ContentBox,
102                align_items: Some(taffy::style::AlignItems::Center),
103                size: taffy::geometry::Size {
104                    width: taffy::style::Dimension::from_length(200f32),
105                    height: taffy::style::Dimension::from_length(200f32),
106                },
107                ..Default::default()
108            },
109            &[node0, node1],
110        )
111        .unwrap();
112    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
113    println!("\nComputed tree:");
114    taffy.print_tree(node);
115    println!();
116    let layout = taffy.layout(node).unwrap();
117    let Layout { size, location, .. } = layout;
118    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
119    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
120    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
121    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
122    let layout = taffy.layout(node0).unwrap();
123    let Layout { size, location, .. } = layout;
124    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node0, 150f32, size.width);
125    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
126    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
127    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
128    let layout = taffy.layout(node1).unwrap();
129    let Layout { size, location, .. } = layout;
130    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
131    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
132    assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node1, 150f32, location.x);
133    assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
134}