tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Sutichaykuna

⎇ float-layout tests/generated/flex/gap_row_gap_row_wrap_child_margins.rs Rust · 145 siq'ikuna · 8.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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