tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ float-layout tests/generated/flex/single_flex_child_after_absolute_child.rs Rust · 144 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 single_flex_child_after_absolute_child__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            position: taffy::style::Position::Absolute,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_percent(1f32),
12                height: taffy::style::Dimension::from_percent(1f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 =
18        taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, flex_shrink: 1f32, ..Default::default() }).unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            flex_shrink: 0f32,
22            flex_basis: taffy::style::Dimension::from_length(174f32),
23            ..Default::default()
24        })
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                flex_direction: taffy::style::FlexDirection::Column,
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::from_length(428f32),
32                    height: taffy::style::Dimension::from_length(845f32),
33                },
34                ..Default::default()
35            },
36            &[node0, node1, node2],
37        )
38        .unwrap();
39    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
40    println!("\nComputed tree:");
41    taffy.print_tree(node);
42    println!();
43    let layout = taffy.layout(node).unwrap();
44    let Layout { size, location, .. } = layout;
45    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node, 428f32, size.width);
46    assert_eq!(size.height, 845f32, "height of node {:?}. Expected {}. Actual {}", node, 845f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
49    let layout = taffy.layout(node0).unwrap();
50    let Layout { size, location, .. } = layout;
51    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node0, 428f32, size.width);
52    assert_eq!(size.height, 845f32, "height of node {:?}. Expected {}. Actual {}", node0, 845f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
55    let layout = taffy.layout(node1).unwrap();
56    let Layout { size, location, .. } = layout;
57    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node1, 428f32, size.width);
58    assert_eq!(size.height, 671f32, "height of node {:?}. Expected {}. Actual {}", node1, 671f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
61    let layout = taffy.layout(node2).unwrap();
62    let Layout { size, location, .. } = layout;
63    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node2, 428f32, size.width);
64    assert_eq!(size.height, 174f32, "height of node {:?}. Expected {}. Actual {}", node2, 174f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
66    assert_eq!(location.y, 671f32, "y of node {:?}. Expected {}. Actual {}", node2, 671f32, location.y);
67}
68
69#[test]
70#[allow(non_snake_case)]
71fn single_flex_child_after_absolute_child__content_box() {
72    #[allow(unused_imports)]
73    use taffy::{prelude::*, Layout};
74    let mut taffy = crate::new_test_tree();
75    let node0 = taffy
76        .new_leaf(taffy::style::Style {
77            box_sizing: taffy::style::BoxSizing::ContentBox,
78            position: taffy::style::Position::Absolute,
79            size: taffy::geometry::Size {
80                width: taffy::style::Dimension::from_percent(1f32),
81                height: taffy::style::Dimension::from_percent(1f32),
82            },
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            flex_shrink: 1f32,
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_shrink: 0f32,
98            flex_basis: taffy::style::Dimension::from_length(174f32),
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                flex_direction: taffy::style::FlexDirection::Column,
107                size: taffy::geometry::Size {
108                    width: taffy::style::Dimension::from_length(428f32),
109                    height: taffy::style::Dimension::from_length(845f32),
110                },
111                ..Default::default()
112            },
113            &[node0, node1, node2],
114        )
115        .unwrap();
116    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
117    println!("\nComputed tree:");
118    taffy.print_tree(node);
119    println!();
120    let layout = taffy.layout(node).unwrap();
121    let Layout { size, location, .. } = layout;
122    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node, 428f32, size.width);
123    assert_eq!(size.height, 845f32, "height of node {:?}. Expected {}. Actual {}", node, 845f32, size.height);
124    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
125    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
126    let layout = taffy.layout(node0).unwrap();
127    let Layout { size, location, .. } = layout;
128    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node0, 428f32, size.width);
129    assert_eq!(size.height, 845f32, "height of node {:?}. Expected {}. Actual {}", node0, 845f32, size.height);
130    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
131    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
132    let layout = taffy.layout(node1).unwrap();
133    let Layout { size, location, .. } = layout;
134    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node1, 428f32, size.width);
135    assert_eq!(size.height, 671f32, "height of node {:?}. Expected {}. Actual {}", node1, 671f32, size.height);
136    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
137    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
138    let layout = taffy.layout(node2).unwrap();
139    let Layout { size, location, .. } = layout;
140    assert_eq!(size.width, 428f32, "width of node {:?}. Expected {}. Actual {}", node2, 428f32, size.width);
141    assert_eq!(size.height, 174f32, "height of node {:?}. Expected {}. Actual {}", node2, 174f32, size.height);
142    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
143    assert_eq!(location.y, 671f32, "y of node {:?}. Expected {}. Actual {}", node2, 671f32, location.y);
144}