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