tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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