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