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