19
19
import SwiftUI
20
20
21
21
/// Grid-based table
22
- public struct TablerGrid < Element, Header, Row, RowBack, Results> : View
22
+ public struct TablerGrid < Element, Header, Row, RowBack, RowOver , Results> : View
23
23
where Element: Identifiable ,
24
24
Header: View ,
25
25
Row: View ,
26
26
RowBack: View ,
27
+ RowOver: View ,
27
28
Results: RandomAccessCollection ,
28
29
Results. Element == Element
29
30
{
@@ -33,25 +34,28 @@ public struct TablerGrid<Element, Header, Row, RowBack, Results>: View
33
34
public typealias HeaderContent = ( Binding < Context > ) -> Header
34
35
public typealias RowContent = ( Element ) -> Row
35
36
public typealias RowBackground = ( Element ) -> RowBack
37
+ public typealias RowOverlay = ( Element ) -> RowOver
36
38
37
39
// MARK: Parameters
38
40
39
41
private let config : Config
40
42
private let headerContent : HeaderContent
41
43
private let rowContent : RowContent
42
44
private let rowBackground : RowBackground
45
+ private let rowOverlay : RowOverlay
43
46
private var results : Results
44
47
45
48
public init ( _ config: Config = . init( ) ,
46
49
@ViewBuilder header: @escaping HeaderContent ,
47
50
@ViewBuilder row: @escaping RowContent ,
48
51
@ViewBuilder rowBackground: @escaping RowBackground ,
49
- results : Results )
50
- {
52
+ @ ViewBuilder rowOverlay : @escaping RowOverlay ,
53
+ results : Results ) {
51
54
self . config = config
52
55
headerContent = header
53
56
rowContent = row
54
57
self . rowBackground = rowBackground
58
+ self . rowOverlay = rowOverlay
55
59
self . results = results
56
60
_context = State ( initialValue: TablerContext ( config) )
57
61
}
@@ -80,41 +84,106 @@ public extension TablerGrid {
80
84
init ( _ config: Config ,
81
85
@ViewBuilder row: @escaping RowContent ,
82
86
@ViewBuilder rowBackground: @escaping RowBackground ,
87
+ @ViewBuilder rowOverlay: @escaping RowOverlay ,
83
88
results: Results )
84
89
where Header == EmptyView
85
90
{
86
91
self . init ( config,
87
92
header: { _ in EmptyView ( ) } ,
88
93
row: row,
89
94
rowBackground: rowBackground,
95
+ rowOverlay: rowOverlay,
96
+ results: results)
97
+ }
98
+
99
+ // omitting Overlay
100
+ init ( _ config: Config ,
101
+ @ViewBuilder header: @escaping HeaderContent ,
102
+ @ViewBuilder row: @escaping RowContent ,
103
+ @ViewBuilder rowBackground: @escaping RowBackground ,
104
+ results: Results )
105
+ where RowOver == EmptyView
106
+ {
107
+ self . init ( config,
108
+ header: header,
109
+ row: row,
110
+ rowBackground: rowBackground,
111
+ rowOverlay: { _ in EmptyView ( ) } ,
90
112
results: results)
91
113
}
92
114
93
115
// omitting Background
94
116
init ( _ config: Config ,
95
117
@ViewBuilder header: @escaping HeaderContent ,
96
118
@ViewBuilder row: @escaping RowContent ,
119
+ @ViewBuilder rowOverlay: @escaping RowOverlay ,
97
120
results: Results )
98
121
where RowBack == EmptyView
99
122
{
100
123
self . init ( config,
101
124
header: header,
102
125
row: row,
103
126
rowBackground: { _ in EmptyView ( ) } ,
127
+ rowOverlay: rowOverlay,
128
+ results: results)
129
+ }
130
+
131
+ // omitting Header AND Overlay
132
+ init ( _ config: Config ,
133
+ @ViewBuilder row: @escaping RowContent ,
134
+ @ViewBuilder rowBackground: @escaping RowBackground ,
135
+ results: Results )
136
+ where Header == EmptyView , RowOver == EmptyView
137
+ {
138
+ self . init ( config,
139
+ header: { _ in EmptyView ( ) } ,
140
+ row: row,
141
+ rowBackground: rowBackground,
142
+ rowOverlay: { _ in EmptyView ( ) } ,
104
143
results: results)
105
144
}
106
145
107
146
// omitting Header AND Background
108
147
init ( _ config: Config ,
109
148
@ViewBuilder row: @escaping RowContent ,
149
+ @ViewBuilder rowOverlay: @escaping RowOverlay ,
110
150
results: Results )
111
151
where Header == EmptyView , RowBack == EmptyView
112
152
{
113
153
self . init ( config,
114
154
header: { _ in EmptyView ( ) } ,
115
155
row: row,
116
156
rowBackground: { _ in EmptyView ( ) } ,
157
+ rowOverlay: rowOverlay,
158
+ results: results)
159
+ }
160
+
161
+ // omitting Background AND Overlay
162
+ init ( _ config: Config ,
163
+ @ViewBuilder header: @escaping HeaderContent ,
164
+ @ViewBuilder row: @escaping RowContent ,
165
+ results: Results )
166
+ where RowBack == EmptyView , RowOver == EmptyView
167
+ {
168
+ self . init ( config,
169
+ header: header,
170
+ row: row,
171
+ rowBackground: { _ in EmptyView ( ) } ,
172
+ rowOverlay: { _ in EmptyView ( ) } ,
117
173
results: results)
118
174
}
119
175
176
+ // omitting Header, Background, AND Overlay
177
+ init ( _ config: Config ,
178
+ @ViewBuilder row: @escaping RowContent ,
179
+ results: Results )
180
+ where Header == EmptyView , RowBack == EmptyView , RowOver == EmptyView
181
+ {
182
+ self . init ( config,
183
+ header: { _ in EmptyView ( ) } ,
184
+ row: row,
185
+ rowBackground: { _ in EmptyView ( ) } ,
186
+ rowOverlay: { _ in EmptyView ( ) } ,
187
+ results: results)
188
+ }
120
189
}
0 commit comments