tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ float-layout tests/generated/leaf/leaf_with_content_and_padding.rs Rust · 64 líneas · 2.8 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 leaf_with_content_and_padding__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node = taffy
8        .new_leaf_with_context(
9            taffy::style::Style {
10                padding: taffy::geometry::Rect {
11                    left: length(8f32),
12                    right: length(4f32),
13                    top: length(2f32),
14                    bottom: length(6f32),
15                },
16                ..Default::default()
17            },
18            crate::TestNodeContext::ahem_text("HHHH", crate::WritingMode::Horizontal),
19        )
20        .unwrap();
21    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
22    println!("\nComputed tree:");
23    taffy.print_tree(node);
24    println!();
25    let layout = taffy.layout(node).unwrap();
26    let Layout { size, location, .. } = layout;
27    assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
28    assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
29    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
30    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
31}
32
33#[test]
34#[allow(non_snake_case)]
35fn leaf_with_content_and_padding__content_box() {
36    #[allow(unused_imports)]
37    use taffy::{prelude::*, Layout};
38    let mut taffy = crate::new_test_tree();
39    let node = taffy
40        .new_leaf_with_context(
41            taffy::style::Style {
42                box_sizing: taffy::style::BoxSizing::ContentBox,
43                padding: taffy::geometry::Rect {
44                    left: length(8f32),
45                    right: length(4f32),
46                    top: length(2f32),
47                    bottom: length(6f32),
48                },
49                ..Default::default()
50            },
51            crate::TestNodeContext::ahem_text("HHHH", crate::WritingMode::Horizontal),
52        )
53        .unwrap();
54    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
55    println!("\nComputed tree:");
56    taffy.print_tree(node);
57    println!();
58    let layout = taffy.layout(node).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
61    assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
64}