tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

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