tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definiciones

⎇ float-layout tests/generated/block/block_absolute_minmax_bottom_right_min_max.rs Rust · 107 líneas · 5.3 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

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