tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/measure_flex_basis_overrides_measure.rs Rust · 84 siq'ikuna · 4.1 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_flex_basis_overrides_measure__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 { ..Default::default() },
10            crate::TestNodeContext::ahem_text("H", 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(50f32),
18                    height: taffy::style::Dimension::from_length(50f32),
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, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
32    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, 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, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
38    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, 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_flex_basis_overrides_measure__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 { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
52            crate::TestNodeContext::ahem_text("H", crate::WritingMode::Horizontal),
53        )
54        .unwrap();
55    let node = taffy
56        .new_with_children(
57            taffy::style::Style {
58                box_sizing: taffy::style::BoxSizing::ContentBox,
59                size: taffy::geometry::Size {
60                    width: taffy::style::Dimension::from_length(50f32),
61                    height: taffy::style::Dimension::from_length(50f32),
62                },
63                ..Default::default()
64            },
65            &[node0],
66        )
67        .unwrap();
68    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
69    println!("\nComputed tree:");
70    taffy.print_tree(node);
71    println!();
72    let layout = taffy.layout(node).unwrap();
73    let Layout { size, location, .. } = layout;
74    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
75    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
76    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
77    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
78    let layout = taffy.layout(node0).unwrap();
79    let Layout { size, location, .. } = layout;
80    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
81    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
82    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
83    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
84}