tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

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