tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1130HTML 550Markdown 11TOML 63111 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_grow_flex_basis_percent_min_max.rs Rust · 126 lines · 6.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_flex_basis_percent_min_max__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: 0f32,
11            flex_basis: taffy::style::Dimension::from_length(0f32),
12            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
13            min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf(taffy::style::Style {
19            flex_grow: 1f32,
20            flex_shrink: 0f32,
21            flex_basis: taffy::style::Dimension::from_percent(0.5f32),
22            size: taffy::geometry::Size {
23                width: taffy::style::Dimension::from_length(20f32),
24                height: taffy::style::Dimension::from_length(20f32),
25            },
26            max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
27            ..Default::default()
28        })
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(120f32), height: auto() },
34                ..Default::default()
35            },
36            &[node0, node1],
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, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
46    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, 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, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
52    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, 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, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
58    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
59    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
61}
62
63#[test]
64#[allow(non_snake_case)]
65fn flex_grow_flex_basis_percent_min_max__content_box() {
66    #[allow(unused_imports)]
67    use taffy::{prelude::*, Layout};
68    let mut taffy = crate::new_test_tree();
69    let node0 = taffy
70        .new_leaf(taffy::style::Style {
71            box_sizing: taffy::style::BoxSizing::ContentBox,
72            flex_grow: 1f32,
73            flex_shrink: 0f32,
74            flex_basis: taffy::style::Dimension::from_length(0f32),
75            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
76            min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
77            ..Default::default()
78        })
79        .unwrap();
80    let node1 = taffy
81        .new_leaf(taffy::style::Style {
82            box_sizing: taffy::style::BoxSizing::ContentBox,
83            flex_grow: 1f32,
84            flex_shrink: 0f32,
85            flex_basis: taffy::style::Dimension::from_percent(0.5f32),
86            size: taffy::geometry::Size {
87                width: taffy::style::Dimension::from_length(20f32),
88                height: taffy::style::Dimension::from_length(20f32),
89            },
90            max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
91            ..Default::default()
92        })
93        .unwrap();
94    let node = taffy
95        .new_with_children(
96            taffy::style::Style {
97                box_sizing: taffy::style::BoxSizing::ContentBox,
98                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(120f32), height: auto() },
99                ..Default::default()
100            },
101            &[node0, node1],
102        )
103        .unwrap();
104    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
105    println!("\nComputed tree:");
106    taffy.print_tree(node);
107    println!();
108    let layout = taffy.layout(node).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
111    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
112    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
114    let layout = taffy.layout(node0).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
117    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
118    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
120    let layout = taffy.layout(node1).unwrap();
121    let Layout { size, location, .. } = layout;
122    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
123    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
124    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
125    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
126}