tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

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