tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91822 Sutichaykuna

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