@@ -28,46 +28,44 @@ struct LayoutProtocolSample: View {
28
28
}
29
29
30
30
struct BackslashStack : Layout {
31
-
32
- func sizeThatFits( proposal: ProposedViewSize , subviews: Subviews , cache: inout ( ) ) -> CGSize {
33
-
31
+ func sizeThatFits( proposal _: ProposedViewSize , subviews: Subviews , cache _: inout ( ) ) -> CGSize {
34
32
let subviewSizes = subviews. map { proxy in
35
- return proxy. sizeThatFits ( . unspecified)
33
+ proxy. sizeThatFits ( . unspecified)
36
34
}
37
-
35
+
38
36
let combinedSize = subviewSizes. reduce ( . zero) { currentSize, subviewSize in
39
-
40
- return CGSize (
41
- width: currentSize. width + subviewSize. width, height: currentSize. height + subviewSize. height)
37
+
38
+ CGSize (
39
+ width: currentSize. width + subviewSize. width, height: currentSize. height + subviewSize. height
40
+ )
42
41
}
43
-
42
+
44
43
return combinedSize
45
44
}
46
-
47
- func placeSubviews( in bounds: CGRect , proposal: ProposedViewSize , subviews: Subviews , cache: inout ( ) ) {
48
-
49
-
45
+
46
+ func placeSubviews( in bounds: CGRect , proposal: ProposedViewSize , subviews: Subviews , cache _: inout ( ) ) {
50
47
let subviewSizes = subviews. map { proxy in
51
- return proxy. sizeThatFits ( . unspecified)
48
+ proxy. sizeThatFits ( . unspecified)
52
49
}
53
-
50
+
54
51
var x = bounds. minX
55
52
var y = bounds. minY
56
-
53
+
57
54
for index in subviews. indices {
58
55
let subviewSize = subviewSizes [ index]
59
56
let sizeProposal = ProposedViewSize (
60
57
width: subviewSize. width,
61
- height: subviewSize. height)
62
-
58
+ height: subviewSize. height
59
+ )
60
+
63
61
subviews [ index]
64
62
. place (
65
63
at: CGPoint ( x: x, y: y) ,
66
- proposal: sizeProposal)
67
-
64
+ proposal: sizeProposal
65
+ )
66
+
68
67
x += subviewSize. width
69
68
y += subviewSize. height
70
69
}
71
70
}
72
-
73
71
}
0 commit comments