tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ direction-floats tests/generated/flex/aspect_ratio_flex_column_fill_max_height.rs Rust · 80 líneas · 4.9 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 aspect_ratio_flex_column_fill_max_height__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: from_length (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
8    let node = taffy
9        .new_with_children(
10            taffy::style::Style {
11                display: taffy::style::Display::Flex,
12                flex_direction: taffy::style::FlexDirection::Column,
13                align_items: Some(taffy::style::AlignItems::Start),
14                size: taffy::geometry::Size {
15                    width: taffy::style::Dimension::from_length(100f32),
16                    height: taffy::style::Dimension::from_length(100f32),
17                },
18                ..Default::default()
19            },
20            &[node0],
21        )
22        .unwrap();
23    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
24    println!("\nComputed tree:");
25    taffy.print_tree(node);
26    println!();
27    let layout = taffy.layout(node).unwrap();
28    let Layout { size, location, .. } = layout;
29    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
30    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
31    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
32    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
33    let layout = taffy.layout(node0).unwrap();
34    let Layout { size, location, .. } = layout;
35    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
36    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
37    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
38    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
39}
40
41#[test]
42#[allow(non_snake_case)]
43fn aspect_ratio_flex_column_fill_max_height__content_box() {
44    #[allow(unused_imports)]
45    use taffy::{prelude::*, Layout};
46    let mut taffy = crate::new_test_tree();
47    let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { box_sizing : taffy :: style :: BoxSizing :: ContentBox , max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: from_length (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
48    let node = taffy
49        .new_with_children(
50            taffy::style::Style {
51                display: taffy::style::Display::Flex,
52                box_sizing: taffy::style::BoxSizing::ContentBox,
53                flex_direction: taffy::style::FlexDirection::Column,
54                align_items: Some(taffy::style::AlignItems::Start),
55                size: taffy::geometry::Size {
56                    width: taffy::style::Dimension::from_length(100f32),
57                    height: taffy::style::Dimension::from_length(100f32),
58                },
59                ..Default::default()
60            },
61            &[node0],
62        )
63        .unwrap();
64    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
65    println!("\nComputed tree:");
66    taffy.print_tree(node);
67    println!();
68    let layout = taffy.layout(node).unwrap();
69    let Layout { size, location, .. } = layout;
70    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
71    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
72    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
74    let layout = taffy.layout(node0).unwrap();
75    let Layout { size, location, .. } = layout;
76    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
77    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
80}