tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

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