tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 735HTML 687Markdown 12TOML 62433 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_basis_flex_shrink_column.rs Rust · 109 lines · 5.6 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 flex_basis_flex_shrink_column__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_basis: taffy::style::Dimension::from_length(100f32),
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style { flex_basis: taffy::style::Dimension::from_length(50f32), ..Default::default() })
15        .unwrap();
16    let node = taffy
17        .new_with_children(
18            taffy::style::Style {
19                flex_direction: taffy::style::FlexDirection::Column,
20                size: taffy::geometry::Size {
21                    width: taffy::style::Dimension::from_length(100f32),
22                    height: taffy::style::Dimension::from_length(100f32),
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
36    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
42    assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
48    assert_eq!(size.height, 33f32, "height of node {:?}. Expected {}. Actual {}", node1, 33f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
50    assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node1, 67f32, location.y);
51}
52
53#[test]
54#[allow(non_snake_case)]
55fn flex_basis_flex_shrink_column__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            box_sizing: taffy::style::BoxSizing::ContentBox,
62            flex_basis: taffy::style::Dimension::from_length(100f32),
63            ..Default::default()
64        })
65        .unwrap();
66    let node1 = taffy
67        .new_leaf(taffy::style::Style {
68            box_sizing: taffy::style::BoxSizing::ContentBox,
69            flex_basis: taffy::style::Dimension::from_length(50f32),
70            ..Default::default()
71        })
72        .unwrap();
73    let node = taffy
74        .new_with_children(
75            taffy::style::Style {
76                box_sizing: taffy::style::BoxSizing::ContentBox,
77                flex_direction: taffy::style::FlexDirection::Column,
78                size: taffy::geometry::Size {
79                    width: taffy::style::Dimension::from_length(100f32),
80                    height: taffy::style::Dimension::from_length(100f32),
81                },
82                ..Default::default()
83            },
84            &[node0, node1],
85        )
86        .unwrap();
87    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
88    println!("\nComputed tree:");
89    taffy.print_tree(node);
90    println!();
91    let layout = taffy.layout(node).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
94    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
97    let layout = taffy.layout(node0).unwrap();
98    let Layout { size, location, .. } = layout;
99    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
100    assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0, 67f32, size.height);
101    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
103    let layout = taffy.layout(node1).unwrap();
104    let Layout { size, location, .. } = layout;
105    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
106    assert_eq!(size.height, 33f32, "height of node {:?}. Expected {}. Actual {}", node1, 33f32, size.height);
107    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
108    assert_eq!(location.y, 67f32, "y of node {:?}. Expected {}. Actual {}", node1, 67f32, location.y);
109}