tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Sutichaykuna

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