tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ float-layout tests/generated/flex/justify_content_column_max_height_and_margin.rs Rust · 112 líneas · 6.2 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 justify_content_column_max_height_and_margin__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(20f32),
11                height: taffy::style::Dimension::from_length(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                flex_direction: taffy::style::FlexDirection::Column,
20                justify_content: Some(taffy::style::JustifyContent::Center),
21                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
22                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(80f32) },
23                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(100f32), bottom: zero() },
24                ..Default::default()
25            },
26            &[node00],
27        )
28        .unwrap();
29    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
30    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
31    println!("\nComputed tree:");
32    taffy.print_tree(node);
33    println!();
34    let layout = taffy.layout(node).unwrap();
35    let Layout { size, location, .. } = layout;
36    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
37    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node, 180f32, size.height);
38    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
39    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
40    let layout = taffy.layout(node0).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
43    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node0, 80f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
45    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
46    let layout = taffy.layout(node00).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
49    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
51    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node00, 30f32, location.y);
52}
53
54#[test]
55#[allow(non_snake_case)]
56fn justify_content_column_max_height_and_margin__content_box() {
57    #[allow(unused_imports)]
58    use taffy::{prelude::*, Layout};
59    let mut taffy = crate::new_test_tree();
60    let node00 = taffy
61        .new_leaf(taffy::style::Style {
62            box_sizing: taffy::style::BoxSizing::ContentBox,
63            size: taffy::geometry::Size {
64                width: taffy::style::Dimension::from_length(20f32),
65                height: taffy::style::Dimension::from_length(20f32),
66            },
67            ..Default::default()
68        })
69        .unwrap();
70    let node0 = taffy
71        .new_with_children(
72            taffy::style::Style {
73                box_sizing: taffy::style::BoxSizing::ContentBox,
74                flex_direction: taffy::style::FlexDirection::Column,
75                justify_content: Some(taffy::style::JustifyContent::Center),
76                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
77                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(80f32) },
78                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(100f32), bottom: zero() },
79                ..Default::default()
80            },
81            &[node00],
82        )
83        .unwrap();
84    let node = taffy
85        .new_with_children(
86            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
87            &[node0],
88        )
89        .unwrap();
90    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
91    println!("\nComputed tree:");
92    taffy.print_tree(node);
93    println!();
94    let layout = taffy.layout(node).unwrap();
95    let Layout { size, location, .. } = layout;
96    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
97    assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node, 180f32, size.height);
98    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
99    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
100    let layout = taffy.layout(node0).unwrap();
101    let Layout { size, location, .. } = layout;
102    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
103    assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node0, 80f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
105    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
106    let layout = taffy.layout(node00).unwrap();
107    let Layout { size, location, .. } = layout;
108    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node00, 20f32, size.width);
109    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
110    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
111    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node00, 30f32, location.y);
112}