tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definiciones

⎇ float-layout tests/generated/flex/size_defined_by_grand_child.rs Rust · 92 líneas · 5.1 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 size_defined_by_grand_child__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(100f32),
11                height: taffy::style::Dimension::from_length(100f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node00]).unwrap();
17    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
18    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
19    println!("\nComputed tree:");
20    taffy.print_tree(node);
21    println!();
22    let layout = taffy.layout(node).unwrap();
23    let Layout { size, location, .. } = layout;
24    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
25    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
26    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
27    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
28    let layout = taffy.layout(node0).unwrap();
29    let Layout { size, location, .. } = layout;
30    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
31    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
32    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
33    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
34    let layout = taffy.layout(node00).unwrap();
35    let Layout { size, location, .. } = layout;
36    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
37    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
38    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
39    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
40}
41
42#[test]
43#[allow(non_snake_case)]
44fn size_defined_by_grand_child__content_box() {
45    #[allow(unused_imports)]
46    use taffy::{prelude::*, Layout};
47    let mut taffy = crate::new_test_tree();
48    let node00 = taffy
49        .new_leaf(taffy::style::Style {
50            box_sizing: taffy::style::BoxSizing::ContentBox,
51            size: taffy::geometry::Size {
52                width: taffy::style::Dimension::from_length(100f32),
53                height: taffy::style::Dimension::from_length(100f32),
54            },
55            ..Default::default()
56        })
57        .unwrap();
58    let node0 = taffy
59        .new_with_children(
60            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
61            &[node00],
62        )
63        .unwrap();
64    let node = taffy
65        .new_with_children(
66            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
67            &[node0],
68        )
69        .unwrap();
70    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
71    println!("\nComputed tree:");
72    taffy.print_tree(node);
73    println!();
74    let layout = taffy.layout(node).unwrap();
75    let Layout { size, location, .. } = layout;
76    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
77    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80    let layout = taffy.layout(node0).unwrap();
81    let Layout { size, location, .. } = layout;
82    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
83    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
84    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
86    let layout = taffy.layout(node00).unwrap();
87    let Layout { size, location, .. } = layout;
88    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
89    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
92}