tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1118HTML 1044Markdown 12TOML 94787 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/measure_child_with_flex_shrink.rs Rust · 121 siq'ikuna · 6.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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