tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

⎇ float-layout tests/generated/flex/justify_content_row_center.rs Rust · 137 lines · 7.4 KB History Who touched what raw

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

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