tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_grow_to_min.rs Rust · 107 siq'ikuna · 5.9 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 flex_grow_to_min__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 =
8        taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, flex_shrink: 1f32, ..Default::default() }).unwrap();
9    let node1 = taffy
10        .new_leaf(taffy::style::Style {
11            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
12            ..Default::default()
13        })
14        .unwrap();
15    let node = taffy
16        .new_with_children(
17            taffy::style::Style {
18                flex_direction: taffy::style::FlexDirection::Column,
19                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
20                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
21                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(500f32) },
22                ..Default::default()
23            },
24            &[node0, node1],
25        )
26        .unwrap();
27    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
28    println!("\nComputed tree:");
29    taffy.print_tree(node);
30    println!();
31    let layout = taffy.layout(node).unwrap();
32    let Layout { size, location, .. } = layout;
33    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
34    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
37    let layout = taffy.layout(node0).unwrap();
38    let Layout { size, location, .. } = layout;
39    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
40    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
41    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
43    let layout = taffy.layout(node1).unwrap();
44    let Layout { size, location, .. } = layout;
45    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
46    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
48    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
49}
50
51#[test]
52#[allow(non_snake_case)]
53fn flex_grow_to_min__content_box() {
54    #[allow(unused_imports)]
55    use taffy::{prelude::*, Layout};
56    let mut taffy = crate::new_test_tree();
57    let node0 = taffy
58        .new_leaf(taffy::style::Style {
59            box_sizing: taffy::style::BoxSizing::ContentBox,
60            flex_grow: 1f32,
61            flex_shrink: 1f32,
62            ..Default::default()
63        })
64        .unwrap();
65    let node1 = taffy
66        .new_leaf(taffy::style::Style {
67            box_sizing: taffy::style::BoxSizing::ContentBox,
68            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
69            ..Default::default()
70        })
71        .unwrap();
72    let node = taffy
73        .new_with_children(
74            taffy::style::Style {
75                box_sizing: taffy::style::BoxSizing::ContentBox,
76                flex_direction: taffy::style::FlexDirection::Column,
77                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
78                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
79                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(500f32) },
80                ..Default::default()
81            },
82            &[node0, node1],
83        )
84        .unwrap();
85    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
86    println!("\nComputed tree:");
87    taffy.print_tree(node);
88    println!();
89    let layout = taffy.layout(node).unwrap();
90    let Layout { size, location, .. } = layout;
91    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
92    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
93    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
94    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
95    let layout = taffy.layout(node0).unwrap();
96    let Layout { size, location, .. } = layout;
97    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
98    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
99    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
100    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
101    let layout = taffy.layout(node1).unwrap();
102    let Layout { size, location, .. } = layout;
103    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
104    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
105    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
106    assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
107}