tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/flex_direction_column_no_height.rs Rust · 131 siq'ikuna · 7.2 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_direction_column_no_height__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            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
10            ..Default::default()
11        })
12        .unwrap();
13    let node1 = taffy
14        .new_leaf(taffy::style::Style {
15            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
16            ..Default::default()
17        })
18        .unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
22            ..Default::default()
23        })
24        .unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                flex_direction: taffy::style::FlexDirection::Column,
29                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
30                ..Default::default()
31            },
32            &[node0, node1, node2],
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, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
48    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, 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(node1).unwrap();
52    let Layout { size, location, .. } = layout;
53    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
54    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
56    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
57    let layout = taffy.layout(node2).unwrap();
58    let Layout { size, location, .. } = layout;
59    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
60    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
62    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
63}
64
65#[test]
66#[allow(non_snake_case)]
67fn flex_direction_column_no_height__content_box() {
68    #[allow(unused_imports)]
69    use taffy::{prelude::*, Layout};
70    let mut taffy = crate::new_test_tree();
71    let node0 = taffy
72        .new_leaf(taffy::style::Style {
73            box_sizing: taffy::style::BoxSizing::ContentBox,
74            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
75            ..Default::default()
76        })
77        .unwrap();
78    let node1 = taffy
79        .new_leaf(taffy::style::Style {
80            box_sizing: taffy::style::BoxSizing::ContentBox,
81            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
82            ..Default::default()
83        })
84        .unwrap();
85    let node2 = taffy
86        .new_leaf(taffy::style::Style {
87            box_sizing: taffy::style::BoxSizing::ContentBox,
88            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
89            ..Default::default()
90        })
91        .unwrap();
92    let node = taffy
93        .new_with_children(
94            taffy::style::Style {
95                box_sizing: taffy::style::BoxSizing::ContentBox,
96                flex_direction: taffy::style::FlexDirection::Column,
97                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
98                ..Default::default()
99            },
100            &[node0, node1, node2],
101        )
102        .unwrap();
103    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
104    println!("\nComputed tree:");
105    taffy.print_tree(node);
106    println!();
107    let layout = taffy.layout(node).unwrap();
108    let Layout { size, location, .. } = layout;
109    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
110    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
111    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
112    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
113    let layout = taffy.layout(node0).unwrap();
114    let Layout { size, location, .. } = layout;
115    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
116    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
117    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
119    let layout = taffy.layout(node1).unwrap();
120    let Layout { size, location, .. } = layout;
121    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
122    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
123    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
124    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
125    let layout = taffy.layout(node2).unwrap();
126    let Layout { size, location, .. } = layout;
127    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
128    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
129    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
130    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
131}