tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

⎇ direction-floats tests/generated/flex/min_height_with_nested_fixed_height.rs Rust · 138 líneas · 7.0 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 min_height_with_nested_fixed_height__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(40f32),
11                height: taffy::style::Dimension::from_length(40f32),
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                align_self: Some(taffy::style::AlignSelf::FlexStart),
21                flex_shrink: 0f32,
22                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(28f32) },
23                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(8f32), bottom: length(9f32) },
24                ..Default::default()
25            },
26            &[node00],
27        )
28        .unwrap();
29    let node = taffy
30        .new_with_children(
31            taffy::style::Style {
32                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(320f32), height: auto() },
33                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(44f32) },
34                padding: taffy::geometry::Rect {
35                    left: length(16f32),
36                    right: length(16f32),
37                    top: zero(),
38                    bottom: zero(),
39                },
40                ..Default::default()
41            },
42            &[node0],
43        )
44        .unwrap();
45    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
46    println!("\nComputed tree:");
47    taffy.print_tree(node);
48    println!();
49    let layout = taffy.layout(node).unwrap();
50    let Layout { size, location, .. } = layout;
51    assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
52    assert_eq!(size.height, 57f32, "height of node {:?}. Expected {}. Actual {}", node, 57f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
55    let layout = taffy.layout(node0).unwrap();
56    let Layout { size, location, .. } = layout;
57    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
58    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
59    assert_eq!(location.x, 16f32, "x of node {:?}. Expected {}. Actual {}", node0, 16f32, location.x);
60    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
61    let layout = taffy.layout(node00).unwrap();
62    let Layout { size, location, .. } = layout;
63    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
64    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
67}
68
69#[test]
70#[allow(non_snake_case)]
71fn min_height_with_nested_fixed_height__content_box() {
72    #[allow(unused_imports)]
73    use taffy::{prelude::*, Layout};
74    let mut taffy = crate::new_test_tree();
75    let node00 = taffy
76        .new_leaf(taffy::style::Style {
77            box_sizing: taffy::style::BoxSizing::ContentBox,
78            size: taffy::geometry::Size {
79                width: taffy::style::Dimension::from_length(40f32),
80                height: taffy::style::Dimension::from_length(40f32),
81            },
82            ..Default::default()
83        })
84        .unwrap();
85    let node0 = taffy
86        .new_with_children(
87            taffy::style::Style {
88                box_sizing: taffy::style::BoxSizing::ContentBox,
89                flex_direction: taffy::style::FlexDirection::Column,
90                align_self: Some(taffy::style::AlignSelf::FlexStart),
91                flex_shrink: 0f32,
92                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(28f32) },
93                margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(8f32), bottom: length(9f32) },
94                ..Default::default()
95            },
96            &[node00],
97        )
98        .unwrap();
99    let node = taffy
100        .new_with_children(
101            taffy::style::Style {
102                box_sizing: taffy::style::BoxSizing::ContentBox,
103                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(320f32), height: auto() },
104                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(44f32) },
105                padding: taffy::geometry::Rect {
106                    left: length(16f32),
107                    right: length(16f32),
108                    top: zero(),
109                    bottom: zero(),
110                },
111                ..Default::default()
112            },
113            &[node0],
114        )
115        .unwrap();
116    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
117    println!("\nComputed tree:");
118    taffy.print_tree(node);
119    println!();
120    let layout = taffy.layout(node).unwrap();
121    let Layout { size, location, .. } = layout;
122    assert_eq!(size.width, 352f32, "width of node {:?}. Expected {}. Actual {}", node, 352f32, size.width);
123    assert_eq!(size.height, 57f32, "height of node {:?}. Expected {}. Actual {}", node, 57f32, size.height);
124    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
125    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
126    let layout = taffy.layout(node0).unwrap();
127    let Layout { size, location, .. } = layout;
128    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
129    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
130    assert_eq!(location.x, 16f32, "x of node {:?}. Expected {}. Actual {}", node0, 16f32, location.x);
131    assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0, 8f32, location.y);
132    let layout = taffy.layout(node00).unwrap();
133    let Layout { size, location, .. } = layout;
134    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node00, 40f32, size.width);
135    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node00, 40f32, size.height);
136    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
137    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
138}