tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ b9fce82ccc823839f673144ed08f2e0e53f52b76 tests/generated/grid_fit_content_percent_indefinite_min_content_hidden.rs Rust · 53 lines · 2.5 KB History Who touched what raw

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

1#[test]
2fn grid_fit_content_percent_indefinite_min_content_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_with_measure(
9            taffy::style::Style {
10                overflow: taffy::geometry::Point {
11                    x: taffy::style::Overflow::Hidden,
12                    y: taffy::style::Overflow::Hidden,
13                },
14                ..Default::default()
15            },
16            taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
17                const TEXT: &str = "HHHH\u{200b}HH";
18                super::measure_standard_text(
19                    known_dimensions,
20                    available_space,
21                    TEXT,
22                    super::WritingMode::Horizontal,
23                    None,
24                )
25            }),
26        )
27        .unwrap();
28    let node = taffy
29        .new_with_children(
30            taffy::style::Style {
31                display: taffy::style::Display::Grid,
32                grid_template_rows: vec![points(40f32)],
33                grid_template_columns: vec![fit_content(percent(0.5f32))],
34                ..Default::default()
35            },
36            &[node0],
37        )
38        .unwrap();
39    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
40    println!("\nComputed tree:");
41    taffy::debug::print_tree(&taffy, node);
42    println!();
43    let Layout { size, location, .. } = taffy.layout(node).unwrap();
44    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.width);
45    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
48    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
49    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.width);
50    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
51    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
52    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
53}