tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

⎇ direction-floats tests/generated/gridflex/gridflex_kitchen_sink_minimise.rs Rust · 118 líneas · 6.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_minimise__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 { width: taffy::style::Dimension::from_length(50f32), height: auto() },
10            ..Default::default()
11        })
12        .unwrap();
13    let node01 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
14    let node0 = taffy
15        .new_with_children(
16            taffy::style::Style {
17                display: taffy::style::Display::Grid,
18                grid_template_rows: vec![length(20f32)],
19                grid_template_columns: vec![fr(1f32), fr(1f32)],
20                ..Default::default()
21            },
22            &[node00, node01],
23        )
24        .unwrap();
25    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
26    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
27    println!("\nComputed tree:");
28    taffy.print_tree(node);
29    println!();
30    let layout = taffy.layout(node).unwrap();
31    let Layout { size, location, .. } = layout;
32    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
33    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
34    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
35    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
36    let layout = taffy.layout(node0).unwrap();
37    let Layout { size, location, .. } = layout;
38    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
39    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
42    let layout = taffy.layout(node00).unwrap();
43    let Layout { size, location, .. } = layout;
44    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
45    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
48    let layout = taffy.layout(node01).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
51    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
52    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
54}
55
56#[test]
57#[allow(non_snake_case)]
58fn gridflex_kitchen_sink_minimise__content_box() {
59    #[allow(unused_imports)]
60    use taffy::{prelude::*, Layout};
61    let mut taffy = crate::new_test_tree();
62    let node00 = taffy
63        .new_leaf(taffy::style::Style {
64            box_sizing: taffy::style::BoxSizing::ContentBox,
65            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
66            ..Default::default()
67        })
68        .unwrap();
69    let node01 = taffy
70        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
71        .unwrap();
72    let node0 = taffy
73        .new_with_children(
74            taffy::style::Style {
75                display: taffy::style::Display::Grid,
76                box_sizing: taffy::style::BoxSizing::ContentBox,
77                grid_template_rows: vec![length(20f32)],
78                grid_template_columns: vec![fr(1f32), fr(1f32)],
79                ..Default::default()
80            },
81            &[node00, node01],
82        )
83        .unwrap();
84    let node = taffy
85        .new_with_children(
86            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
87            &[node0],
88        )
89        .unwrap();
90    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
91    println!("\nComputed tree:");
92    taffy.print_tree(node);
93    println!();
94    let layout = taffy.layout(node).unwrap();
95    let Layout { size, location, .. } = layout;
96    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
97    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
98    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
100    let layout = taffy.layout(node0).unwrap();
101    let Layout { size, location, .. } = layout;
102    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
103    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
106    let layout = taffy.layout(node00).unwrap();
107    let Layout { size, location, .. } = layout;
108    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
109    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
110    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
111    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
112    let layout = taffy.layout(node01).unwrap();
113    let Layout { size, location, .. } = layout;
114    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node01, 50f32, size.width);
115    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node01, 20f32, size.height);
116    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node01, 50f32, location.x);
117    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
118}