⎇ float-layout
tests/generated/flex/measure_child_with_flex_shrink_hidden.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn measure_child_with_flex_shrink_hidden__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 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(50f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf_with_context(
18 taffy::style::Style {
19 overflow: taffy::geometry::Point {
20 x: taffy::style::Overflow::Hidden,
21 y: taffy::style::Overflow::Hidden,
22 },
23 scrollbar_width: 15f32,
24 ..Default::default()
25 },
26 crate::TestNodeContext::ahem_text(
27 "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH",
28 crate::WritingMode::Horizontal,
29 ),
30 )
31 .unwrap();
32 let node = taffy
33 .new_with_children(
34 taffy::style::Style {
35 size: taffy::geometry::Size {
36 width: taffy::style::Dimension::from_length(100f32),
37 height: taffy::style::Dimension::AUTO,
38 },
39 ..Default::default()
40 },
41 &[node0, node1],
42 )
43 .unwrap();
44 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45 println!("\nComputed tree:");
46 taffy.print_tree(node);
47 println!();
48 let layout = taffy.layout(node).unwrap();
49 let Layout { size, location, .. } = layout;
50 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
51 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
52 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54 let layout = taffy.layout(node0).unwrap();
55 let Layout { size, location, .. } = layout;
56 assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node0, 9f32, size.width);
57 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
60 let layout = taffy.layout(node1).unwrap();
61 let Layout { size, location, .. } = layout;
62 assert_eq!(size.width, 91f32, "width of node {:?}. Expected {}. Actual {}", node1, 91f32, size.width);
63 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
64 assert_eq!(location.x, 9f32, "x of node {:?}. Expected {}. Actual {}", node1, 9f32, location.x);
65 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
66 #[cfg(feature = "content_size")]
67 assert_eq!(
68 layout.scroll_width(),
69 9f32,
70 "scroll_width of node {:?}. Expected {}. Actual {}",
71 node1,
72 9f32,
73 layout.scroll_width()
74 );
75 #[cfg(feature = "content_size")]
76 assert_eq!(
77 layout.scroll_height(),
78 0f32,
79 "scroll_height of node {:?}. Expected {}. Actual {}",
80 node1,
81 0f32,
82 layout.scroll_height()
83 );
84}
85
86#[test]
87#[allow(non_snake_case)]
88fn measure_child_with_flex_shrink_hidden__content_box() {
89 #[allow(unused_imports)]
90 use taffy::{prelude::*, Layout};
91 let mut taffy = crate::new_test_tree();
92 let node0 = taffy
93 .new_leaf(taffy::style::Style {
94 box_sizing: taffy::style::BoxSizing::ContentBox,
95 size: taffy::geometry::Size {
96 width: taffy::style::Dimension::from_length(50f32),
97 height: taffy::style::Dimension::from_length(50f32),
98 },
99 ..Default::default()
100 })
101 .unwrap();
102 let node1 = taffy
103 .new_leaf_with_context(
104 taffy::style::Style {
105 box_sizing: taffy::style::BoxSizing::ContentBox,
106 overflow: taffy::geometry::Point {
107 x: taffy::style::Overflow::Hidden,
108 y: taffy::style::Overflow::Hidden,
109 },
110 scrollbar_width: 15f32,
111 ..Default::default()
112 },
113 crate::TestNodeContext::ahem_text(
114 "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH",
115 crate::WritingMode::Horizontal,
116 ),
117 )
118 .unwrap();
119 let node = taffy
120 .new_with_children(
121 taffy::style::Style {
122 box_sizing: taffy::style::BoxSizing::ContentBox,
123 size: taffy::geometry::Size {
124 width: taffy::style::Dimension::from_length(100f32),
125 height: taffy::style::Dimension::AUTO,
126 },
127 ..Default::default()
128 },
129 &[node0, node1],
130 )
131 .unwrap();
132 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
133 println!("\nComputed tree:");
134 taffy.print_tree(node);
135 println!();
136 let layout = taffy.layout(node).unwrap();
137 let Layout { size, location, .. } = layout;
138 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
139 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
140 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
141 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
142 let layout = taffy.layout(node0).unwrap();
143 let Layout { size, location, .. } = layout;
144 assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node0, 9f32, size.width);
145 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
146 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
147 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
148 let layout = taffy.layout(node1).unwrap();
149 let Layout { size, location, .. } = layout;
150 assert_eq!(size.width, 91f32, "width of node {:?}. Expected {}. Actual {}", node1, 91f32, size.width);
151 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
152 assert_eq!(location.x, 9f32, "x of node {:?}. Expected {}. Actual {}", node1, 9f32, location.x);
153 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
154 #[cfg(feature = "content_size")]
155 assert_eq!(
156 layout.scroll_width(),
157 9f32,
158 "scroll_width of node {:?}. Expected {}. Actual {}",
159 node1,
160 9f32,
161 layout.scroll_width()
162 );
163 #[cfg(feature = "content_size")]
164 assert_eq!(
165 layout.scroll_height(),
166 0f32,
167 "scroll_height of node {:?}. Expected {}. Actual {}",
168 node1,
169 0f32,
170 layout.scroll_height()
171 );
172}