tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1118HTML 1044Markdown 12TOML 94787 Definitions

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