tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Sutichaykuna

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