tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_basis_overrides_main_size.rs Rust · 143 siq'ikuna · 7.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn flex_basis_overrides_main_size__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_grow: 1f32,
10            flex_basis: taffy::style::Dimension::from_length(50f32),
11            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            flex_grow: 1f32,
18            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(10f32), height: auto() },
19            ..Default::default()
20        })
21        .unwrap();
22    let node2 = taffy
23        .new_leaf(taffy::style::Style {
24            flex_grow: 1f32,
25            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(10f32), height: auto() },
26            ..Default::default()
27        })
28        .unwrap();
29    let node = taffy
30        .new_with_children(
31            taffy::style::Style {
32                size: taffy::geometry::Size {
33                    width: taffy::style::Dimension::from_length(100f32),
34                    height: taffy::style::Dimension::from_length(100f32),
35                },
36                ..Default::default()
37            },
38            &[node0, node1, node2],
39        )
40        .unwrap();
41    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42    println!("\nComputed tree:");
43    taffy.print_tree(node);
44    println!();
45    let layout = taffy.layout(node).unwrap();
46    let Layout { size, location, .. } = layout;
47    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
48    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    let layout = taffy.layout(node0).unwrap();
52    let Layout { size, location, .. } = layout;
53    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
54    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
57    let layout = taffy.layout(node1).unwrap();
58    let Layout { size, location, .. } = layout;
59    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
60    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
61    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node1, 60f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
63    let layout = taffy.layout(node2).unwrap();
64    let Layout { size, location, .. } = layout;
65    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
66    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
67    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
69}
70
71#[test]
72#[allow(non_snake_case)]
73fn flex_basis_overrides_main_size__content_box() {
74    #[allow(unused_imports)]
75    use taffy::{prelude::*, Layout};
76    let mut taffy = crate::new_test_tree();
77    let node0 = taffy
78        .new_leaf(taffy::style::Style {
79            box_sizing: taffy::style::BoxSizing::ContentBox,
80            flex_grow: 1f32,
81            flex_basis: taffy::style::Dimension::from_length(50f32),
82            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
83            ..Default::default()
84        })
85        .unwrap();
86    let node1 = taffy
87        .new_leaf(taffy::style::Style {
88            box_sizing: taffy::style::BoxSizing::ContentBox,
89            flex_grow: 1f32,
90            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(10f32), height: auto() },
91            ..Default::default()
92        })
93        .unwrap();
94    let node2 = taffy
95        .new_leaf(taffy::style::Style {
96            box_sizing: taffy::style::BoxSizing::ContentBox,
97            flex_grow: 1f32,
98            size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(10f32), height: auto() },
99            ..Default::default()
100        })
101        .unwrap();
102    let node = taffy
103        .new_with_children(
104            taffy::style::Style {
105                box_sizing: taffy::style::BoxSizing::ContentBox,
106                size: taffy::geometry::Size {
107                    width: taffy::style::Dimension::from_length(100f32),
108                    height: taffy::style::Dimension::from_length(100f32),
109                },
110                ..Default::default()
111            },
112            &[node0, node1, node2],
113        )
114        .unwrap();
115    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
116    println!("\nComputed tree:");
117    taffy.print_tree(node);
118    println!();
119    let layout = taffy.layout(node).unwrap();
120    let Layout { size, location, .. } = layout;
121    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
122    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
124    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
125    let layout = taffy.layout(node0).unwrap();
126    let Layout { size, location, .. } = layout;
127    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
128    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
129    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
130    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
131    let layout = taffy.layout(node1).unwrap();
132    let Layout { size, location, .. } = layout;
133    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
134    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
135    assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node1, 60f32, location.x);
136    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
137    let layout = taffy.layout(node2).unwrap();
138    let Layout { size, location, .. } = layout;
139    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
140    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
141    assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node2, 80f32, location.x);
142    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
143}