tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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