@@ -44,7 +44,15 @@ public struct FixedColumnsGridStyle: GridStyle {
44
44
}
45
45
46
46
public func gridHeight( with geometry: GeometryProxy , itemsCount: Int ) -> CGFloat {
47
- self . gridHeight ( with: geometry, itemsCount: itemsCount, columns: self . columns, itemHeight: self . itemHeight, padding: self . padding, hSpacing: self . hSpacing)
47
+ self . gridHeight (
48
+ with: geometry,
49
+ itemsCount: itemsCount,
50
+ columns: self . columns,
51
+ itemHeight: self . itemHeight,
52
+ padding: self . padding,
53
+ hSpacing: self . hSpacing,
54
+ vSpacing: self . vSpacing
55
+ )
48
56
}
49
57
50
58
@inlinable func availableWidth( with geometry: GeometryProxy , padding: EdgeInsets , hSpacing: CGFloat ) -> CGFloat {
@@ -56,19 +64,21 @@ public struct FixedColumnsGridStyle: GridStyle {
56
64
let row = index / max( 1 , columns)
57
65
let itemIndexAtRow = index % max( 1 , columns)
58
66
let itemWidth = self . itemWidth ( for: geometry, columns: columns, padding: padding, hSpacing: hSpacing)
59
- let x = ( ( itemWidth / 2 ) + CGFloat( itemIndexAtRow) * itemWidth) + padding. leading
67
+ let hSpacingForItem = CGFloat ( itemIndexAtRow) * hSpacing
68
+ let x = ( ( itemWidth / 2 ) + CGFloat( itemIndexAtRow) * itemWidth) + padding. leading + hSpacingForItem
60
69
let y = ( ( itemHeight / 2 ) + CGFloat( row) * itemHeight) + padding. top + ( CGFloat ( row) * vSpacing)
61
70
return CGPoint ( x: x, y: y)
62
71
}
63
72
64
73
@inlinable func itemWidth( for geometry: GeometryProxy , columns: Int , padding: EdgeInsets , hSpacing: CGFloat ) -> CGFloat {
65
74
let availableWidth = self . availableWidth ( with: geometry, padding: padding, hSpacing: hSpacing)
66
- return availableWidth / CGFloat( columns)
75
+ let usableWidth = availableWidth - ( CGFloat ( columns - 1 ) * hSpacing)
76
+ return usableWidth / CGFloat( columns)
67
77
}
68
78
69
- @inlinable func gridHeight( with geometry: GeometryProxy , itemsCount: Int , columns: Int , itemHeight: CGFloat , padding: EdgeInsets , hSpacing: CGFloat ) -> CGFloat {
79
+ @inlinable func gridHeight( with geometry: GeometryProxy , itemsCount: Int , columns: Int , itemHeight: CGFloat , padding: EdgeInsets , hSpacing: CGFloat , vSpacing : CGFloat ) -> CGFloat {
70
80
let rowCount = Int ( ( CGFloat ( itemsCount) / max( 1.0 , CGFloat ( columns) ) ) . rounded ( . up) )
71
81
let verticalPadding = padding. top + padding. bottom
72
- return CGFloat ( rowCount) * itemHeight + verticalPadding
82
+ return CGFloat ( rowCount) * itemHeight + verticalPadding + ( CGFloat ( rowCount - 1 ) * vSpacing )
73
83
}
74
84
}
0 commit comments