gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ d875f416d56489ce545e5051d049603592195a63 tests/generated/flex/align_baseline_double_nested_child.rs Rust · 185 lines · 7.2 KB History Who touched what raw

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn align_baseline_double_nested_child() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(50f32),
10                height: taffy::style::Dimension::Length(20f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style {
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::Length(50f32),
20                    height: taffy::style::Dimension::Length(50f32),
21                },
22                ..Default::default()
23            },
24            &[node00],
25        )
26        .unwrap();
27    let node10 = taffy
28        .new_leaf(taffy::style::Style {
29            size: taffy::geometry::Size {
30                width: taffy::style::Dimension::Length(50f32),
31                height: taffy::style::Dimension::Length(15f32),
32            },
33            ..Default::default()
34        })
35        .unwrap();
36    let node1 = taffy
37        .new_with_children(
38            taffy::style::Style {
39                size: taffy::geometry::Size {
40                    width: taffy::style::Dimension::Length(50f32),
41                    height: taffy::style::Dimension::Length(20f32),
42                },
43                ..Default::default()
44            },
45            &[node10],
46        )
47        .unwrap();
48    let node = taffy
49        .new_with_children(
50            taffy::style::Style {
51                align_items: Some(taffy::style::AlignItems::Baseline),
52                size: taffy::geometry::Size {
53                    width: taffy::style::Dimension::Length(100f32),
54                    height: taffy::style::Dimension::Length(100f32),
55                },
56                ..Default::default()
57            },
58            &[node0, node1],
59        )
60        .unwrap();
61    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
62    println!("\nComputed tree:");
63    taffy.print_tree(node);
64    println!();
65    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
66    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
67    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
68    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
71    #[cfg(feature = "content_size")]
72    assert_eq!(
73        layout.scroll_width(),
74        0f32,
75        "scroll_width of node {:?}. Expected {}. Actual {}",
76        node,
77        0f32,
78        layout.scroll_width()
79    );
80    #[cfg(feature = "content_size")]
81    assert_eq!(
82        layout.scroll_height(),
83        0f32,
84        "scroll_height of node {:?}. Expected {}. Actual {}",
85        node,
86        0f32,
87        layout.scroll_height()
88    );
89    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
90    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
91    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
92    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
95    #[cfg(feature = "content_size")]
96    assert_eq!(
97        layout.scroll_width(),
98        0f32,
99        "scroll_width of node {:?}. Expected {}. Actual {}",
100        node0,
101        0f32,
102        layout.scroll_width()
103    );
104    #[cfg(feature = "content_size")]
105    assert_eq!(
106        layout.scroll_height(),
107        0f32,
108        "scroll_height of node {:?}. Expected {}. Actual {}",
109        node0,
110        0f32,
111        layout.scroll_height()
112    );
113    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
114    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
115    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
116    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
117    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
119    #[cfg(feature = "content_size")]
120    assert_eq!(
121        layout.scroll_width(),
122        0f32,
123        "scroll_width of node {:?}. Expected {}. Actual {}",
124        node00,
125        0f32,
126        layout.scroll_width()
127    );
128    #[cfg(feature = "content_size")]
129    assert_eq!(
130        layout.scroll_height(),
131        0f32,
132        "scroll_height of node {:?}. Expected {}. Actual {}",
133        node00,
134        0f32,
135        layout.scroll_height()
136    );
137    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
138    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
139    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
140    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
141    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
142    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y);
143    #[cfg(feature = "content_size")]
144    assert_eq!(
145        layout.scroll_width(),
146        0f32,
147        "scroll_width of node {:?}. Expected {}. Actual {}",
148        node1,
149        0f32,
150        layout.scroll_width()
151    );
152    #[cfg(feature = "content_size")]
153    assert_eq!(
154        layout.scroll_height(),
155        0f32,
156        "scroll_height of node {:?}. Expected {}. Actual {}",
157        node1,
158        0f32,
159        layout.scroll_height()
160    );
161    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
162    let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
163    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
164    assert_eq!(size.height, 15f32, "height of node {:?}. Expected {}. Actual {}", node10, 15f32, size.height);
165    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
166    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
167    #[cfg(feature = "content_size")]
168    assert_eq!(
169        layout.scroll_width(),
170        0f32,
171        "scroll_width of node {:?}. Expected {}. Actual {}",
172        node10,
173        0f32,
174        layout.scroll_width()
175    );
176    #[cfg(feature = "content_size")]
177    assert_eq!(
178        layout.scroll_height(),
179        0f32,
180        "scroll_height of node {:?}. Expected {}. Actual {}",
181        node10,
182        0f32,
183        layout.scroll_height()
184    );
185}