tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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