tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Definiciones

⎇ float-layout tests/generated/flex/measure_child_absolute.rs Rust · 88 líneas · 4.2 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 measure_child_absolute__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_with_context(
9            taffy::style::Style { position: taffy::style::Position::Absolute, ..Default::default() },
10            crate::TestNodeContext::ahem_text("HHHHHH", crate::WritingMode::Horizontal),
11        )
12        .unwrap();
13    let node = taffy
14        .new_with_children(
15            taffy::style::Style {
16                size: taffy::geometry::Size {
17                    width: taffy::style::Dimension::from_length(100f32),
18                    height: taffy::style::Dimension::from_length(100f32),
19                },
20                ..Default::default()
21            },
22            &[node0],
23        )
24        .unwrap();
25    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
26    println!("\nComputed tree:");
27    taffy.print_tree(node);
28    println!();
29    let layout = taffy.layout(node).unwrap();
30    let Layout { size, location, .. } = layout;
31    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
32    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
33    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35    let layout = taffy.layout(node0).unwrap();
36    let Layout { size, location, .. } = layout;
37    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
38    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
39    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
40    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
41}
42
43#[test]
44#[allow(non_snake_case)]
45fn measure_child_absolute__content_box() {
46    #[allow(unused_imports)]
47    use taffy::{prelude::*, Layout};
48    let mut taffy = crate::new_test_tree();
49    let node0 = taffy
50        .new_leaf_with_context(
51            taffy::style::Style {
52                box_sizing: taffy::style::BoxSizing::ContentBox,
53                position: taffy::style::Position::Absolute,
54                ..Default::default()
55            },
56            crate::TestNodeContext::ahem_text("HHHHHH", crate::WritingMode::Horizontal),
57        )
58        .unwrap();
59    let node = taffy
60        .new_with_children(
61            taffy::style::Style {
62                box_sizing: taffy::style::BoxSizing::ContentBox,
63                size: taffy::geometry::Size {
64                    width: taffy::style::Dimension::from_length(100f32),
65                    height: taffy::style::Dimension::from_length(100f32),
66                },
67                ..Default::default()
68            },
69            &[node0],
70        )
71        .unwrap();
72    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
73    println!("\nComputed tree:");
74    taffy.print_tree(node);
75    println!();
76    let layout = taffy.layout(node).unwrap();
77    let Layout { size, location, .. } = layout;
78    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
79    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
82    let layout = taffy.layout(node0).unwrap();
83    let Layout { size, location, .. } = layout;
84    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
85    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
86    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
87    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
88}