tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 735HTML 687Markdown 12TOML 62433 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/justify_content_column_min_height_and_margin.rs Rust · 110 siq'ikuna · 6.0 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_column_min_height_and_margin__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(20f32),
11                height: taffy::style::Dimension::from_length(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = 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                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
22                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(100f32), bottom: zero() },
23                ..Default::default()
24            },
25            &[node00],
26        )
27        .unwrap();
28    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).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, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
36    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node, 150f32, 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, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
42    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
44    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
45    let layout = taffy.layout(node00).unwrap();
46    let Layout { size, location, .. } = layout;
47    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
48    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
50    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node00, 15f32, location.y);
51}
52
53#[test]
54#[allow(non_snake_case)]
55fn justify_content_column_min_height_and_margin__content_box() {
56    #[allow(unused_imports)]
57    use taffy::{prelude::*, Layout};
58    let mut taffy = crate::new_test_tree();
59    let node00 = taffy
60        .new_leaf(taffy::style::Style {
61            box_sizing: taffy::style::BoxSizing::ContentBox,
62            size: taffy::geometry::Size {
63                width: taffy::style::Dimension::from_length(20f32),
64                height: taffy::style::Dimension::from_length(20f32),
65            },
66            ..Default::default()
67        })
68        .unwrap();
69    let node0 = taffy
70        .new_with_children(
71            taffy::style::Style {
72                box_sizing: taffy::style::BoxSizing::ContentBox,
73                flex_direction: taffy::style::FlexDirection::Column,
74                justify_content: Some(taffy::style::JustifyContent::Center),
75                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(50f32) },
76                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(100f32), bottom: zero() },
77                ..Default::default()
78            },
79            &[node00],
80        )
81        .unwrap();
82    let node = taffy
83        .new_with_children(
84            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
85            &[node0],
86        )
87        .unwrap();
88    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
89    println!("\nComputed tree:");
90    taffy.print_tree(node);
91    println!();
92    let layout = taffy.layout(node).unwrap();
93    let Layout { size, location, .. } = layout;
94    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
95    assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node, 150f32, size.height);
96    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
97    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
98    let layout = taffy.layout(node0).unwrap();
99    let Layout { size, location, .. } = layout;
100    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
101    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
102    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
103    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
104    let layout = taffy.layout(node00).unwrap();
105    let Layout { size, location, .. } = layout;
106    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
107    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
108    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
109    assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node00, 15f32, location.y);
110}