tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definitions

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