tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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