⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/flex/align_items_min_max.rs
Historia
Quién tocó qué
crudo
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn align_items_min_max__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(60f32),
11 height: taffy::style::Dimension::Length(60f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node = taffy
17 .new_with_children(
18 taffy::style::Style {
19 flex_direction: taffy::style::FlexDirection::Column,
20 align_items: Some(taffy::style::AlignItems::Center),
21 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
22 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
23 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
24 ..Default::default()
25 },
26 &[node0],
27 )
28 .unwrap();
29 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
30 println!("\nComputed tree:");
31 taffy.print_tree(node);
32 println!();
33 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
34 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
35 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
36 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
37 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
38 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
39 #[cfg(feature = "content_size")]
40 assert_eq!(
41 layout.scroll_width(),
42 0f32,
43 "scroll_width of node {:?}. Expected {}. Actual {}",
44 node,
45 0f32,
46 layout.scroll_width()
47 );
48 #[cfg(feature = "content_size")]
49 assert_eq!(
50 layout.scroll_height(),
51 0f32,
52 "scroll_height of node {:?}. Expected {}. Actual {}",
53 node,
54 0f32,
55 layout.scroll_height()
56 );
57 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
58 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
59 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
60 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0, 60f32, size.height);
61 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0, 20f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
63 #[cfg(feature = "content_size")]
64 assert_eq!(
65 layout.scroll_width(),
66 0f32,
67 "scroll_width of node {:?}. Expected {}. Actual {}",
68 node0,
69 0f32,
70 layout.scroll_width()
71 );
72 #[cfg(feature = "content_size")]
73 assert_eq!(
74 layout.scroll_height(),
75 0f32,
76 "scroll_height of node {:?}. Expected {}. Actual {}",
77 node0,
78 0f32,
79 layout.scroll_height()
80 );
81}
82
83#[test]
84#[allow(non_snake_case)]
85fn align_items_min_max__content_box() {
86 #[allow(unused_imports)]
87 use taffy::{prelude::*, tree::Layout, TaffyTree};
88 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
89 let node0 = taffy
90 .new_leaf(taffy::style::Style {
91 box_sizing: taffy::style::BoxSizing::ContentBox,
92 size: taffy::geometry::Size {
93 width: taffy::style::Dimension::Length(60f32),
94 height: taffy::style::Dimension::Length(60f32),
95 },
96 ..Default::default()
97 })
98 .unwrap();
99 let node = taffy
100 .new_with_children(
101 taffy::style::Style {
102 box_sizing: taffy::style::BoxSizing::ContentBox,
103 flex_direction: taffy::style::FlexDirection::Column,
104 align_items: Some(taffy::style::AlignItems::Center),
105 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
106 min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
107 max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
108 ..Default::default()
109 },
110 &[node0],
111 )
112 .unwrap();
113 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
114 println!("\nComputed tree:");
115 taffy.print_tree(node);
116 println!();
117 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
118 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
119 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
120 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
121 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
122 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
123 #[cfg(feature = "content_size")]
124 assert_eq!(
125 layout.scroll_width(),
126 0f32,
127 "scroll_width of node {:?}. Expected {}. Actual {}",
128 node,
129 0f32,
130 layout.scroll_width()
131 );
132 #[cfg(feature = "content_size")]
133 assert_eq!(
134 layout.scroll_height(),
135 0f32,
136 "scroll_height of node {:?}. Expected {}. Actual {}",
137 node,
138 0f32,
139 layout.scroll_height()
140 );
141 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
142 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
143 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
144 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0, 60f32, size.height);
145 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0, 20f32, location.x);
146 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
147 #[cfg(feature = "content_size")]
148 assert_eq!(
149 layout.scroll_width(),
150 0f32,
151 "scroll_width of node {:?}. Expected {}. Actual {}",
152 node0,
153 0f32,
154 layout.scroll_width()
155 );
156 #[cfg(feature = "content_size")]
157 assert_eq!(
158 layout.scroll_height(),
159 0f32,
160 "scroll_height of node {:?}. Expected {}. Actual {}",
161 node0,
162 0f32,
163 layout.scroll_height()
164 );
165}