gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 498HTML 238Markdown 7TOML 31230 Definiciones

⎇ 48e4800f14c6af5cd26275fb570d11b93e279654 tests/generated/flex/aspect_ratio_flex_column_fill_max_width.rs Rust · 54 líneas · 2.6 KB Historia Quién tocó qué crudo

Make test measure function non-generated (move to tests/fixtures.rs) (#529) 4fb530bdd · Nico Burns ·

1#[test]
2fn aspect_ratio_flex_column_fill_max_width() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf_with_measure(
8            taffy::style::Style {
9                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
10                aspect_ratio: Some(2f32),
11                ..Default::default()
12            },
13            taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
14                const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
15                crate::measure_standard_text(
16                    known_dimensions,
17                    available_space,
18                    TEXT,
19                    crate::WritingMode::Horizontal,
20                    Some(2f32),
21                )
22            }),
23        )
24        .unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Flex,
29                flex_direction: taffy::style::FlexDirection::Column,
30                align_items: Some(taffy::style::AlignItems::Start),
31                size: taffy::geometry::Size {
32                    width: taffy::style::Dimension::Length(100f32),
33                    height: taffy::style::Dimension::Length(100f32),
34                },
35                ..Default::default()
36            },
37            &[node0],
38        )
39        .unwrap();
40    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
41    println!("\nComputed tree:");
42    taffy::util::print_tree(&taffy, node);
43    println!();
44    let Layout { size, location, .. } = taffy.layout(node).unwrap();
45    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
46    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
49    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
50    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
51    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
54}