tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ b9fce82ccc823839f673144ed08f2e0e53f52b76 tests/generated/measure_child_with_flex_shrink_hidden.rs Rust · 68 líneas · 3.3 KB Historia Quién tocó qué crudo

Support `Overflow::Hidden` (#424) b9fce82cc · Nico Burns ·

1#[test]
2fn measure_child_with_flex_shrink_hidden() {
3    use slotmap::Key;
4    #[allow(unused_imports)]
5    use taffy::{layout::Layout, prelude::*};
6    let mut taffy = taffy::Taffy::new();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Points(50f32),
11                height: taffy::style::Dimension::Points(50f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf_with_measure(
18            taffy::style::Style {
19                overflow: taffy::geometry::Point {
20                    x: taffy::style::Overflow::Hidden,
21                    y: taffy::style::Overflow::Hidden,
22                },
23                ..Default::default()
24            },
25            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
26                const TEXT: &str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH";
27                super::measure_standard_text(
28                    known_dimensions,
29                    available_space,
30                    TEXT,
31                    super::WritingMode::Horizontal,
32                    None,
33                )
34            }),
35        )
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                size: taffy::geometry::Size {
41                    width: taffy::style::Dimension::Points(100f32),
42                    height: taffy::style::Dimension::Auto,
43                },
44                ..Default::default()
45            },
46            &[node0, node1],
47        )
48        .unwrap();
49    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
50    println!("\nComputed tree:");
51    taffy::debug::print_tree(&taffy, node);
52    println!();
53    let Layout { size, location, .. } = taffy.layout(node).unwrap();
54    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
55    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 50f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
58    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
59    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 9f32, size.width);
60    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
63    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
64    assert_eq!(size.width, 91f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 91f32, size.width);
65    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height);
66    assert_eq!(location.x, 9f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 9f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
68}