tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 583HTML 275Markdown 8TOML 41586 Sutichaykuna

⎇ float-layout tests/generated/flex/measure_child_constraint.rs Rust · 74 siq'ikuna · 4.4 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_constraint__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
8    let node = taffy
9        .new_with_children(
10            taffy::style::Style {
11                size: taffy::geometry::Size {
12                    width: taffy::style::Dimension::from_length(50f32),
13                    height: taffy::style::Dimension::AUTO,
14                },
15                ..Default::default()
16            },
17            &[node0],
18        )
19        .unwrap();
20    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
21    println!("\nComputed tree:");
22    taffy.print_tree(node);
23    println!();
24    let layout = taffy.layout(node).unwrap();
25    let Layout { size, location, .. } = layout;
26    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
27    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
28    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
29    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
30    let layout = taffy.layout(node0).unwrap();
31    let Layout { size, location, .. } = layout;
32    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
33    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
34    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
35    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
36}
37
38#[test]
39#[allow(non_snake_case)]
40fn measure_child_constraint__content_box() {
41    #[allow(unused_imports)]
42    use taffy::{prelude::*, Layout};
43    let mut taffy = crate::new_test_tree();
44    let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { box_sizing : taffy :: style :: BoxSizing :: ContentBox , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
45    let node = taffy
46        .new_with_children(
47            taffy::style::Style {
48                box_sizing: taffy::style::BoxSizing::ContentBox,
49                size: taffy::geometry::Size {
50                    width: taffy::style::Dimension::from_length(50f32),
51                    height: taffy::style::Dimension::AUTO,
52                },
53                ..Default::default()
54            },
55            &[node0],
56        )
57        .unwrap();
58    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
59    println!("\nComputed tree:");
60    taffy.print_tree(node);
61    println!();
62    let layout = taffy.layout(node).unwrap();
63    let Layout { size, location, .. } = layout;
64    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
65    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
68    let layout = taffy.layout(node0).unwrap();
69    let Layout { size, location, .. } = layout;
70    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
71    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
72    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
74}