tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ 0.7.x tests/generated/grid/grid_percent_items_nested_with_margin.rs Rust · 126 líneas · 6.5 KB Historia Quién tocó qué crudo

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_percent_items_nested_with_margin__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::Percent(0.45f32), height: auto() },
10            margin: taffy::geometry::Rect {
11                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15            },
16            ..Default::default()
17        })
18        .unwrap();
19    let node0 = taffy
20        .new_with_children(
21            taffy::style::Style {
22                display: taffy::style::Display::Grid,
23                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
24                ..Default::default()
25            },
26            &[node00],
27        )
28        .unwrap();
29    let node = taffy
30        .new_with_children(
31            taffy::style::Style {
32                display: taffy::style::Display::Grid,
33                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), 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, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
46    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
52    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, 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, 45f32, "width of node {:?}. Expected {}. Actual {}", node00, 45f32, size.width);
58    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
59    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
60    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
61}
62
63#[test]
64#[allow(non_snake_case)]
65fn grid_percent_items_nested_with_margin__content_box() {
66    #[allow(unused_imports)]
67    use taffy::{prelude::*, Layout};
68    let mut taffy = crate::new_test_tree();
69    let node00 = taffy
70        .new_leaf(taffy::style::Style {
71            box_sizing: taffy::style::BoxSizing::ContentBox,
72            size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
73            margin: taffy::geometry::Rect {
74                left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
75                right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
76                top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
77                bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
78            },
79            ..Default::default()
80        })
81        .unwrap();
82    let node0 = taffy
83        .new_with_children(
84            taffy::style::Style {
85                display: taffy::style::Display::Grid,
86                box_sizing: taffy::style::BoxSizing::ContentBox,
87                size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
88                ..Default::default()
89            },
90            &[node00],
91        )
92        .unwrap();
93    let node = taffy
94        .new_with_children(
95            taffy::style::Style {
96                display: taffy::style::Display::Grid,
97                box_sizing: taffy::style::BoxSizing::ContentBox,
98                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
99                ..Default::default()
100            },
101            &[node0],
102        )
103        .unwrap();
104    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
105    println!("\nComputed tree:");
106    taffy.print_tree(node);
107    println!();
108    let layout = taffy.layout(node).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
111    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
112    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
114    let layout = taffy.layout(node0).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
117    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
118    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
120    let layout = taffy.layout(node00).unwrap();
121    let Layout { size, location, .. } = layout;
122    assert_eq!(size.width, 45f32, "width of node {:?}. Expected {}. Actual {}", node00, 45f32, size.width);
123    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node00, 0f32, size.height);
124    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00, 5f32, location.x);
125    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00, 5f32, location.y);
126}