tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definitions

⎇ morphorm tests/generated/blockflex/blockflex_overflow_hidden.rs Rust · 67 lines · 3.3 KB History Who touched what raw

Replace per-node measure functions with a single measure function + per-node context (#490) be627e7fa · Nico Burns ·

1#[test]
2fn blockflex_overflow_hidden() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, Taffy};
5    let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6    let node0 = taffy
7        .new_leaf_with_context(
8            taffy::style::Style {
9                display: taffy::style::Display::Block,
10                overflow: taffy::geometry::Point {
11                    x: taffy::style::Overflow::Hidden,
12                    y: taffy::style::Overflow::Hidden,
13                },
14                scrollbar_width: 15f32,
15                flex_grow: 1f32,
16                ..Default::default()
17            },
18            crate::TextMeasure {
19                text_content: "HHHH\u{200b}HH",
20                writing_mode: crate::WritingMode::Horizontal,
21                _aspect_ratio: None,
22            },
23        )
24        .unwrap();
25    let node1 = taffy
26        .new_leaf_with_context(
27            taffy::style::Style { display: taffy::style::Display::Block, flex_grow: 1f32, ..Default::default() },
28            crate::TextMeasure {
29                text_content: "HHHH\u{200b}HH",
30                writing_mode: crate::WritingMode::Horizontal,
31                _aspect_ratio: None,
32            },
33        )
34        .unwrap();
35    let node = taffy
36        .new_with_children(
37            taffy::style::Style {
38                display: taffy::style::Display::Flex,
39                size: taffy::geometry::Size {
40                    width: taffy::style::Dimension::Length(20f32),
41                    height: taffy::style::Dimension::Length(50f32),
42                },
43                ..Default::default()
44            },
45            &[node0, node1],
46        )
47        .unwrap();
48    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
49    println!("\nComputed tree:");
50    taffy.print_tree(node);
51    println!();
52    let Layout { size, location, .. } = taffy.layout(node).unwrap();
53    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
54    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
58    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
59    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
62    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
63    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
64    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
67}