tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

⎇ float-layout tests/generated/flex/gap_column_gap_start_index.rs Rust · 184 lines · 9.6 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 gap_column_gap_start_index__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            position: taffy::style::Position::Absolute,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(20f32),
12                height: taffy::style::Dimension::from_length(20f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf(taffy::style::Style {
19            size: taffy::geometry::Size {
20                width: taffy::style::Dimension::from_length(20f32),
21                height: taffy::style::Dimension::from_length(20f32),
22            },
23            ..Default::default()
24        })
25        .unwrap();
26    let node2 = taffy
27        .new_leaf(taffy::style::Style {
28            size: taffy::geometry::Size {
29                width: taffy::style::Dimension::from_length(20f32),
30                height: taffy::style::Dimension::from_length(20f32),
31            },
32            ..Default::default()
33        })
34        .unwrap();
35    let node3 = taffy
36        .new_leaf(taffy::style::Style {
37            size: taffy::geometry::Size {
38                width: taffy::style::Dimension::from_length(20f32),
39                height: taffy::style::Dimension::from_length(20f32),
40            },
41            ..Default::default()
42        })
43        .unwrap();
44    let node = taffy
45        .new_with_children(
46            taffy::style::Style {
47                flex_wrap: taffy::style::FlexWrap::Wrap,
48                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
49                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(80f32), height: auto() },
50                ..Default::default()
51            },
52            &[node0, node1, node2, node3],
53        )
54        .unwrap();
55    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
56    println!("\nComputed tree:");
57    taffy.print_tree(node);
58    println!();
59    let layout = taffy.layout(node).unwrap();
60    let Layout { size, location, .. } = layout;
61    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
62    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
65    let layout = taffy.layout(node0).unwrap();
66    let Layout { size, location, .. } = layout;
67    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
68    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
71    let layout = taffy.layout(node1).unwrap();
72    let Layout { size, location, .. } = layout;
73    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
74    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
75    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
76    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
77    let layout = taffy.layout(node2).unwrap();
78    let Layout { size, location, .. } = layout;
79    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
80    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
81    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node2, 30f32, location.x);
82    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
83    let layout = taffy.layout(node3).unwrap();
84    let Layout { size, location, .. } = layout;
85    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
86    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
87    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3, 60f32, location.x);
88    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
89}
90
91#[test]
92#[allow(non_snake_case)]
93fn gap_column_gap_start_index__content_box() {
94    #[allow(unused_imports)]
95    use taffy::{prelude::*, Layout};
96    let mut taffy = crate::new_test_tree();
97    let node0 = taffy
98        .new_leaf(taffy::style::Style {
99            box_sizing: taffy::style::BoxSizing::ContentBox,
100            position: taffy::style::Position::Absolute,
101            size: taffy::geometry::Size {
102                width: taffy::style::Dimension::from_length(20f32),
103                height: taffy::style::Dimension::from_length(20f32),
104            },
105            ..Default::default()
106        })
107        .unwrap();
108    let node1 = taffy
109        .new_leaf(taffy::style::Style {
110            box_sizing: taffy::style::BoxSizing::ContentBox,
111            size: taffy::geometry::Size {
112                width: taffy::style::Dimension::from_length(20f32),
113                height: taffy::style::Dimension::from_length(20f32),
114            },
115            ..Default::default()
116        })
117        .unwrap();
118    let node2 = taffy
119        .new_leaf(taffy::style::Style {
120            box_sizing: taffy::style::BoxSizing::ContentBox,
121            size: taffy::geometry::Size {
122                width: taffy::style::Dimension::from_length(20f32),
123                height: taffy::style::Dimension::from_length(20f32),
124            },
125            ..Default::default()
126        })
127        .unwrap();
128    let node3 = taffy
129        .new_leaf(taffy::style::Style {
130            box_sizing: taffy::style::BoxSizing::ContentBox,
131            size: taffy::geometry::Size {
132                width: taffy::style::Dimension::from_length(20f32),
133                height: taffy::style::Dimension::from_length(20f32),
134            },
135            ..Default::default()
136        })
137        .unwrap();
138    let node = taffy
139        .new_with_children(
140            taffy::style::Style {
141                box_sizing: taffy::style::BoxSizing::ContentBox,
142                flex_wrap: taffy::style::FlexWrap::Wrap,
143                gap: taffy::geometry::Size { width: length(10f32), height: length(20f32) },
144                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(80f32), height: auto() },
145                ..Default::default()
146            },
147            &[node0, node1, node2, node3],
148        )
149        .unwrap();
150    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
151    println!("\nComputed tree:");
152    taffy.print_tree(node);
153    println!();
154    let layout = taffy.layout(node).unwrap();
155    let Layout { size, location, .. } = layout;
156    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
157    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
158    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
159    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
160    let layout = taffy.layout(node0).unwrap();
161    let Layout { size, location, .. } = layout;
162    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
163    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
164    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
165    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
166    let layout = taffy.layout(node1).unwrap();
167    let Layout { size, location, .. } = layout;
168    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
169    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
170    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
171    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
172    let layout = taffy.layout(node2).unwrap();
173    let Layout { size, location, .. } = layout;
174    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
175    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
176    assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node2, 30f32, location.x);
177    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
178    let layout = taffy.layout(node3).unwrap();
179    let Layout { size, location, .. } = layout;
180    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node3, 20f32, size.width);
181    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node3, 20f32, size.height);
182    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node3, 60f32, location.x);
183    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y);
184}