tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Definiciones

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