@@ -5,110 +5,53 @@ use float_pigment_layout::{DefLength, OptionNum, OptionSize};
5
5
unsafe fn as_ref < ' a > ( node : * mut Node ) -> & ' a Node {
6
6
& * node
7
7
}
8
+
8
9
#[ test]
9
10
pub fn aspect_ratio_in_flex_row ( ) {
10
- unsafe {
11
- let root = as_ref ( Node :: new_ptr ( ) ) ;
12
-
13
- let container = as_ref ( Node :: new_ptr ( ) ) ;
14
- container. set_width ( DefLength :: Points ( Len :: from_f32 ( 700. ) ) ) ;
15
- container. set_height ( DefLength :: Points ( Len :: from_f32 ( 300. ) ) ) ;
16
- container. set_display ( Display :: Flex ) ;
17
- container. set_flex_direction ( FlexDirection :: Row ) ;
18
- root. append_child ( convert_node_ref_to_ptr ( container) ) ;
19
-
20
- let child_a = as_ref ( Node :: new_ptr ( ) ) ;
21
- child_a. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
22
- child_a. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
23
- child_a. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
24
- container. append_child ( convert_node_ref_to_ptr ( child_a) ) ;
25
-
26
- let child_b = as_ref ( Node :: new_ptr ( ) ) ;
27
- child_b. set_width ( DefLength :: Auto ) ;
28
- child_b. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
29
- child_b. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
30
- container. append_child ( convert_node_ref_to_ptr ( child_b) ) ;
31
-
32
- let child_c = as_ref ( Node :: new_ptr ( ) ) ;
33
- child_c. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
34
- child_c. set_height ( DefLength :: Auto ) ;
35
- child_c. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
36
- container. append_child ( convert_node_ref_to_ptr ( child_c) ) ;
37
-
38
- let child_d = as_ref ( Node :: new_ptr ( ) ) ;
39
- child_d. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
40
- child_d. set_height ( DefLength :: Auto ) ;
41
- child_d. set_align_self ( AlignSelf :: FlexStart ) ;
42
- child_d. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
43
- container. append_child ( convert_node_ref_to_ptr ( child_d) ) ;
44
-
45
- root. layout (
46
- OptionSize :: new ( OptionNum :: some ( Len :: from_f32 ( 800. ) ) , OptionNum :: none ( ) ) ,
47
- Size :: new ( Len :: from_f32 ( 0. ) , Len :: from_f32 ( 0. ) ) ,
48
- ) ;
49
- println ! (
50
- "{}" ,
51
- root. dump_to_html(
52
- DumpOptions {
53
- recursive: true ,
54
- layout: true ,
55
- style: DumpStyleMode :: None
56
- } ,
57
- 0
58
- )
59
- ) ;
60
-
61
- assert_eq ! ( child_a. layout_position( ) . width, 100. ) ;
62
- assert_eq ! ( child_a. layout_position( ) . height, 100. ) ;
63
-
64
- assert_eq ! ( child_b. layout_position( ) . width, 75. ) ;
65
- assert_eq ! ( child_b. layout_position( ) . height, 100. ) ;
66
-
67
- assert_eq ! ( child_c. layout_position( ) . width, 100. ) ;
68
- assert_eq ! ( child_c. layout_position( ) . height, 300. ) ;
69
-
70
- assert_eq ! ( child_d. layout_position( ) . width, 100. ) ;
71
- assert_eq ! ( child_d. layout_position( ) . height. round( ) , 133. ) ;
72
- }
11
+ assert_xml ! (
12
+ r#"
13
+ <div style="width: 700px; height: 300px; display: flex; flex-direction: row;">
14
+ <div style="width: 100px; height: 100px; aspect-ratio: 0.75 / 1;" expect_width="100" expect_height="100"></div>
15
+ <div style="width: auto; height: 100px; aspect-ratio: 0.75 / 1;" expect_width="75" expect_height="100"></div>
16
+ <div style="width: 100px; height: auto; aspect-ratio: 0.75 / 1;" expect_width="100" expect_height="300"></div>
17
+ <div style="width: 100px; height: auto; aspect-ratio: 0.75 / 1; align-self: flex-start" expect_width="100" expect_height="133"></div>
18
+ </div>
19
+ "#
20
+ )
73
21
}
74
22
75
23
#[ test]
76
24
pub fn aspect_ratio_in_flex_column ( ) {
25
+ assert_xml ! (
26
+ r#"
27
+ <div style="width: 300px; height: 600px; display: flex; flex-direction: column;">
28
+ <div style="width: 100px; height: 100px; aspect-ratio: 0.75 / 1;" expect_width="100" expect_height="100"></div>
29
+ <div style="width: auto; height: 100px; aspect-ratio: 0.75 / 1;" expect_width="300" expect_height="100"></div>
30
+ <div style="width: auto; height: 100px; aspect-ratio: 0.75 / 1; align-self: flex-start" expect_width="75" expect_height="100"></div>
31
+ <div style="width: 100px; height: auto; aspect-ratio: 0.75 / 1;" expect_width="100" expect_height="133"></div>
32
+ </div>
33
+ "#
34
+ )
35
+ }
36
+
37
+ #[ test]
38
+ pub fn aspect_ratio_with_flex_1 ( ) {
77
39
unsafe {
78
40
let root = as_ref ( Node :: new_ptr ( ) ) ;
79
41
80
42
let container = as_ref ( Node :: new_ptr ( ) ) ;
81
- container. set_width ( DefLength :: Points ( Len :: from_f32 ( 300. ) ) ) ;
82
- container. set_height ( DefLength :: Points ( Len :: from_f32 ( 600. ) ) ) ;
43
+ container. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
83
44
container. set_display ( Display :: Flex ) ;
84
45
container. set_flex_direction ( FlexDirection :: Column ) ;
85
46
root. append_child ( convert_node_ref_to_ptr ( container) ) ;
86
47
87
48
let child_a = as_ref ( Node :: new_ptr ( ) ) ;
88
- child_a. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
89
- child_a. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
90
- child_a. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
49
+ child_a. set_width ( DefLength :: Points ( Len :: from_f32 ( 50. ) ) ) ;
50
+ child_a. set_min_width ( DefLength :: Points ( Len :: from_f32 ( 0. ) ) ) ;
51
+ child_a. set_flex_basis ( DefLength :: Percent ( 0. ) ) ;
52
+ child_a. set_aspect_ratio ( Some ( 1. / 1. ) ) ;
91
53
container. append_child ( convert_node_ref_to_ptr ( child_a) ) ;
92
54
93
- let child_b = as_ref ( Node :: new_ptr ( ) ) ;
94
- child_b. set_width ( DefLength :: Auto ) ;
95
- child_b. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
96
- child_b. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
97
- container. append_child ( convert_node_ref_to_ptr ( child_b) ) ;
98
-
99
- let child_c = as_ref ( Node :: new_ptr ( ) ) ;
100
- child_c. set_width ( DefLength :: Auto ) ;
101
- child_c. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
102
- child_c. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
103
- child_c. set_align_self ( AlignSelf :: FlexStart ) ;
104
- container. append_child ( convert_node_ref_to_ptr ( child_c) ) ;
105
-
106
- let child_d = as_ref ( Node :: new_ptr ( ) ) ;
107
- child_d. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
108
- child_d. set_height ( DefLength :: Auto ) ;
109
- child_d. set_aspect_ratio ( Some ( 0.75 / 1. ) ) ;
110
- container. append_child ( convert_node_ref_to_ptr ( child_d) ) ;
111
-
112
55
root. layout (
113
56
OptionSize :: new ( OptionNum :: some ( Len :: from_f32 ( 375. ) ) , OptionNum :: none ( ) ) ,
114
57
Size :: new ( Len :: from_f32 ( 0. ) , Len :: from_f32 ( 0. ) ) ,
@@ -125,35 +68,30 @@ pub fn aspect_ratio_in_flex_column() {
125
68
)
126
69
) ;
127
70
128
- assert_eq ! ( child_a. layout_position( ) . width, 100. ) ;
129
- assert_eq ! ( child_a. layout_position( ) . height, 100. ) ;
130
-
131
- assert_eq ! ( child_b. layout_position( ) . width, 300. ) ;
132
- assert_eq ! ( child_b. layout_position( ) . height, 100. ) ;
133
-
134
- assert_eq ! ( child_c. layout_position( ) . width, 75. ) ;
135
- assert_eq ! ( child_c. layout_position( ) . height, 100. ) ;
136
-
137
- assert_eq ! ( child_d. layout_position( ) . width, 100. ) ;
138
- assert_eq ! ( child_d. layout_position( ) . height. round( ) , 133. ) ;
71
+ assert_eq ! ( child_a. layout_position( ) . width, 50. ) ;
72
+ assert_eq ! ( child_a. layout_position( ) . height, 50. ) ;
139
73
}
140
74
}
141
75
142
76
#[ test]
143
- pub fn aspect_ratio_with_flex_1 ( ) {
77
+ pub fn aspect_ratio_with_flex_wrap ( ) {
144
78
unsafe {
145
79
let root = as_ref ( Node :: new_ptr ( ) ) ;
146
80
147
81
let container = as_ref ( Node :: new_ptr ( ) ) ;
148
- container. set_width ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
82
+ container. set_height ( DefLength :: Points ( Len :: from_f32 ( 100. ) ) ) ;
149
83
container. set_display ( Display :: Flex ) ;
150
84
container. set_flex_direction ( FlexDirection :: Column ) ;
85
+ container. set_flex_wrap ( FlexWrap :: Wrap ) ;
86
+ container. set_align_items ( AlignItems :: Stretch ) ;
151
87
root. append_child ( convert_node_ref_to_ptr ( container) ) ;
152
88
153
89
let child_a = as_ref ( Node :: new_ptr ( ) ) ;
154
- child_a. set_width ( DefLength :: Points ( Len :: from_f32 ( 50. ) ) ) ;
90
+ child_a. set_height ( DefLength :: Points ( Len :: from_f32 ( 50. ) ) ) ;
155
91
child_a. set_min_width ( DefLength :: Points ( Len :: from_f32 ( 0. ) ) ) ;
156
92
child_a. set_flex_basis ( DefLength :: Percent ( 0. ) ) ;
93
+ child_a. set_flex_shrink ( 1. ) ;
94
+ child_a. set_flex_grow ( 1. ) ;
157
95
child_a. set_aspect_ratio ( Some ( 1. / 1. ) ) ;
158
96
container. append_child ( convert_node_ref_to_ptr ( child_a) ) ;
159
97
@@ -173,30 +111,25 @@ pub fn aspect_ratio_with_flex_1() {
173
111
)
174
112
) ;
175
113
176
- assert_eq ! ( child_a. layout_position( ) . width, 50 .) ;
177
- assert_eq ! ( child_a. layout_position( ) . height, 50 .) ;
114
+ assert_eq ! ( child_a. layout_position( ) . width, 100 .) ;
115
+ assert_eq ! ( child_a. layout_position( ) . height, 100 .) ;
178
116
}
179
117
}
180
118
181
119
#[ test]
182
- pub fn aspect_ratio_with_flex_wrap ( ) {
120
+ pub fn aspect_ratio_with_flex_no_wrap_1 ( ) {
183
121
unsafe {
184
122
let root = as_ref ( Node :: new_ptr ( ) ) ;
185
123
186
124
let container = as_ref ( Node :: new_ptr ( ) ) ;
187
- container. set_height ( DefLength :: Points ( Len :: from_f32 ( 100 .) ) ) ;
125
+ container. set_height ( DefLength :: Points ( Len :: from_f32 ( 50 .) ) ) ;
188
126
container. set_display ( Display :: Flex ) ;
189
127
container. set_flex_direction ( FlexDirection :: Column ) ;
190
- container. set_flex_wrap ( FlexWrap :: Wrap ) ;
128
+ container. set_flex_wrap ( FlexWrap :: NoWrap ) ;
191
129
container. set_align_items ( AlignItems :: Stretch ) ;
192
130
root. append_child ( convert_node_ref_to_ptr ( container) ) ;
193
131
194
132
let child_a = as_ref ( Node :: new_ptr ( ) ) ;
195
- child_a. set_height ( DefLength :: Points ( Len :: from_f32 ( 50. ) ) ) ;
196
- child_a. set_min_width ( DefLength :: Points ( Len :: from_f32 ( 0. ) ) ) ;
197
- child_a. set_flex_basis ( DefLength :: Percent ( 0. ) ) ;
198
- child_a. set_flex_shrink ( 1. ) ;
199
- child_a. set_flex_grow ( 1. ) ;
200
133
child_a. set_aspect_ratio ( Some ( 1. / 1. ) ) ;
201
134
container. append_child ( convert_node_ref_to_ptr ( child_a) ) ;
202
135
@@ -216,48 +149,13 @@ pub fn aspect_ratio_with_flex_wrap() {
216
149
)
217
150
) ;
218
151
219
- assert_eq ! ( child_a. layout_position( ) . width, 100 .) ;
220
- assert_eq ! ( child_a. layout_position( ) . height, 100 .) ;
152
+ assert_eq ! ( child_a. layout_position( ) . width, 375 .) ;
153
+ assert_eq ! ( child_a. layout_position( ) . height, 50 .) ;
221
154
}
222
155
}
223
156
224
- // #[test]
225
- // pub fn aspect_ratio_1() {
226
- // unsafe {
227
- // let root = as_ref(Node::new_ptr(Some(0), None));
228
-
229
- // let container = as_ref(Node::new_ptr(Some(1), None));
230
- // container.set_height(DefLength::Points(50.));
231
- // container.set_display(Display::Flex);
232
- // container.set_flex_direction(FlexDirection::Column);
233
- // container.set_flex_wrap(FlexWrap::NoWrap);
234
- // container.set_align_items(AlignItems::Stretch);
235
- // root.append_child(container.self_ptr().unwrap());
236
-
237
- // let child_a = as_ref(Node::new_ptr(Some(2), None));
238
- // child_a.set_aspect_ratio(AspectRatio::Ratio(Number::F32(1.), Number::F32(1.)));
239
- // container.append_child(child_a.self_ptr().unwrap());
240
-
241
- // root.layout(OptionNum::some(375.), OptionNum::none());
242
- // println!(
243
- // "{}",
244
- // root.dump_to_html(
245
- // DumpOptions {
246
- // recursive: true,
247
- // layout: true,
248
- // style: DumpStyleMode::None
249
- // },
250
- // 0
251
- // )
252
- // );
253
-
254
- // assert_eq!(child_a.layout_position().width, 375.);
255
- // assert_eq!(child_a.layout_position().height, 50.);
256
- // }
257
- // }
258
-
259
157
#[ test]
260
- pub fn aspect_ratio_2 ( ) {
158
+ pub fn aspect_ratio_with_flex_no_wrap_2 ( ) {
261
159
unsafe {
262
160
let root = as_ref ( Node :: new_ptr ( ) ) ;
263
161
@@ -659,7 +557,7 @@ pub fn aspect_ratio_block_size_with_box_sizing_and_writing_mode() {
659
557
}
660
558
661
559
#[ test]
662
- pub fn apsect_ratio_writing_mode_streched ( ) {
560
+ pub fn aspect_ratio_writing_mode_stretched ( ) {
663
561
assert_xml ! (
664
562
r#"
665
563
<div>
0 commit comments