⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/flex/child_min_max_width_flexing.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn child_min_max_width_flexing__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 flex_grow: 1f32,
10 flex_shrink: 0f32,
11 flex_basis: taffy::style::Dimension::from_length(0f32),
12 min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 flex_grow: 1f32,
19 flex_shrink: 0f32,
20 flex_basis: taffy::style::Dimension::from_percent(0.5f32),
21 max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
22 ..Default::default()
23 })
24 .unwrap();
25 let node = taffy
26 .new_with_children(
27 taffy::style::Style {
28 align_items: Some(taffy::style::AlignItems::Stretch),
29 size: taffy::geometry::Size {
30 width: taffy::style::Dimension::from_length(120f32),
31 height: taffy::style::Dimension::from_length(50f32),
32 },
33 ..Default::default()
34 },
35 &[node0, node1],
36 )
37 .unwrap();
38 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
39 println!("\nComputed tree:");
40 taffy.print_tree(node);
41 println!();
42 let layout = taffy.layout(node).unwrap();
43 let Layout { size, location, .. } = layout;
44 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
45 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48 let layout = taffy.layout(node0).unwrap();
49 let Layout { size, location, .. } = layout;
50 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
51 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, 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 let layout = taffy.layout(node1).unwrap();
55 let Layout { size, location, .. } = layout;
56 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
57 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
58 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
60}
61
62#[test]
63#[allow(non_snake_case)]
64fn child_min_max_width_flexing__content_box() {
65 #[allow(unused_imports)]
66 use taffy::{prelude::*, Layout};
67 let mut taffy = crate::new_test_tree();
68 let node0 = taffy
69 .new_leaf(taffy::style::Style {
70 box_sizing: taffy::style::BoxSizing::ContentBox,
71 flex_grow: 1f32,
72 flex_shrink: 0f32,
73 flex_basis: taffy::style::Dimension::from_length(0f32),
74 min_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
75 ..Default::default()
76 })
77 .unwrap();
78 let node1 = taffy
79 .new_leaf(taffy::style::Style {
80 box_sizing: taffy::style::BoxSizing::ContentBox,
81 flex_grow: 1f32,
82 flex_shrink: 0f32,
83 flex_basis: taffy::style::Dimension::from_percent(0.5f32),
84 max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(20f32), height: auto() },
85 ..Default::default()
86 })
87 .unwrap();
88 let node = taffy
89 .new_with_children(
90 taffy::style::Style {
91 box_sizing: taffy::style::BoxSizing::ContentBox,
92 align_items: Some(taffy::style::AlignItems::Stretch),
93 size: taffy::geometry::Size {
94 width: taffy::style::Dimension::from_length(120f32),
95 height: taffy::style::Dimension::from_length(50f32),
96 },
97 ..Default::default()
98 },
99 &[node0, node1],
100 )
101 .unwrap();
102 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
103 println!("\nComputed tree:");
104 taffy.print_tree(node);
105 println!();
106 let layout = taffy.layout(node).unwrap();
107 let Layout { size, location, .. } = layout;
108 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
109 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
110 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
111 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
112 let layout = taffy.layout(node0).unwrap();
113 let Layout { size, location, .. } = layout;
114 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
115 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
116 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
117 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
118 let layout = taffy.layout(node1).unwrap();
119 let Layout { size, location, .. } = layout;
120 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
121 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
122 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
123 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
124}