@@ -5,26 +5,28 @@ import SwiftUI
55struct ListHeaderStyle : ViewModifier {
66 let height : CGFloat
77 let padding : EdgeInsets
8+ let opaque : Bool
89
9- init ( height: CGFloat = 36 , padding: EdgeInsets ? = nil ) {
10+ init ( height: CGFloat = 36 , padding: EdgeInsets ? = nil , opaque : Bool = false ) {
1011 self . height = height
1112 self . padding = padding ?? EdgeInsets ( top: 8 , leading: 12 , bottom: 8 , trailing: 12 )
13+ self . opaque = opaque
1214 }
1315
1416 func body( content: Content ) -> some View {
1517 content
1618 . padding ( padding)
1719 . frame ( maxWidth: . infinity)
1820 . frame ( height: height)
19- . background ( Color ( NSColor . clear) )
21+ . background ( opaque ? Color ( NSColor . controlBackgroundColor ) : Color ( NSColor . clear) )
2022 }
2123}
2224
2325// MARK: - View Extension
2426
2527extension View {
26- func listHeaderStyle( height: CGFloat = 36 , padding: EdgeInsets ? = nil ) -> some View {
27- modifier ( ListHeaderStyle ( height: height, padding: padding) )
28+ func listHeaderStyle( height: CGFloat = 36 , padding: EdgeInsets ? = nil , opaque : Bool = false ) -> some View {
29+ modifier ( ListHeaderStyle ( height: height, padding: padding, opaque : opaque ) )
2830 }
2931}
3032
@@ -39,17 +41,20 @@ struct ListHeader<Content: View>: View {
3941 let type : HeaderType
4042 let height : CGFloat ?
4143 let padding : EdgeInsets ?
44+ let opaque : Bool
4245 let content : ( ) -> Content
4346
4447 init (
4548 type: HeaderType = . simple,
4649 height: CGFloat ? = nil ,
4750 padding: EdgeInsets ? = nil ,
51+ opaque: Bool = false ,
4852 @ViewBuilder content: @escaping ( ) -> Content
4953 ) {
5054 self . type = type
5155 self . height = height
5256 self . padding = padding
57+ self . opaque = opaque
5358 self . content = content
5459 }
5560
@@ -59,7 +64,8 @@ struct ListHeader<Content: View>: View {
5964 }
6065 . listHeaderStyle (
6166 height: height ?? ( type == . simple ? 36 : 120 ) ,
62- padding: padding
67+ padding: padding,
68+ opaque: opaque
6369 )
6470 }
6571}
@@ -99,92 +105,73 @@ struct EntityHeader<Content: View>: View {
99105struct TrackListHeader < Trailing: View > : View {
100106 let title : String
101107 let subtitle : String ?
102- let trackCount : Int
108+ let trackCount : Int ?
109+ let sortOrder : Binding < [ KeyPathComparator < Track > ] > ?
110+ let tableRowSize : Binding < TableRowSize > ?
103111 let trailing : ( ( ) -> Trailing ) ?
104112
113+ // With sort options + trailing content
105114 init (
106115 title: String ,
107116 subtitle: String ? = nil ,
108- trackCount: Int ,
109- @ViewBuilder trailing: @escaping ( ) -> Trailing
117+ sortOrder: Binding < [ KeyPathComparator < Track > ] > ,
118+ tableRowSize: Binding < TableRowSize > ,
119+ @ViewBuilder trailingContent: @escaping ( ) -> Trailing
110120 ) {
111121 self . title = title
112122 self . subtitle = subtitle
113- self . trackCount = trackCount
114- self . trailing = trailing
123+ self . trackCount = nil
124+ self . sortOrder = sortOrder
125+ self . tableRowSize = tableRowSize
126+ self . trailing = trailingContent
115127 }
116128
129+ // With sort options, no trailing content
117130 init (
118131 title: String ,
119132 subtitle: String ? = nil ,
120- trackCount: Int
133+ sortOrder: Binding < [ KeyPathComparator < Track > ] > ,
134+ tableRowSize: Binding < TableRowSize >
121135 ) where Trailing == EmptyView {
122136 self . title = title
123137 self . subtitle = subtitle
124- self . trackCount = trackCount
138+ self . trackCount = nil
139+ self . sortOrder = sortOrder
140+ self . tableRowSize = tableRowSize
125141 self . trailing = nil
126142 }
127143
128- var body : some View {
129- ListHeader {
130- VStack ( alignment: . leading, spacing: 2 ) {
131- Text ( title)
132- . headerTitleStyle ( )
133-
134- if let subtitle = subtitle {
135- Text ( subtitle)
136- . headerSubtitleStyle ( )
137- }
138- }
139-
140- Spacer ( )
141-
142- if let trailing = trailing {
143- trailing ( )
144- } else {
145- Text ( " \( trackCount) tracks " )
146- . headerSubtitleStyle ( )
147- }
148- }
149- }
150- }
151-
152- struct TrackListHeaderWithOptions < TrailingContent: View > : View {
153- let title : String
154- let subtitle : String ?
155- @Binding var sortOrder : [ KeyPathComparator < Track > ]
156- @Binding var tableRowSize : TableRowSize
157- let trailingContent : TrailingContent
158-
144+ // With track count + trailing content, no sort options
159145 init (
160146 title: String ,
161147 subtitle: String ? = nil ,
162- sortOrder: Binding < [ KeyPathComparator < Track > ] > ,
163- tableRowSize: Binding < TableRowSize > ,
164- @ViewBuilder trailingContent: ( ) -> TrailingContent
148+ trackCount: Int ,
149+ @ViewBuilder trailing: @escaping ( ) -> Trailing
165150 ) {
166151 self . title = title
167152 self . subtitle = subtitle
168- self . _sortOrder = sortOrder
169- self . _tableRowSize = tableRowSize
170- self . trailingContent = trailingContent ( )
153+ self . trackCount = trackCount
154+ self . sortOrder = nil
155+ self . tableRowSize = nil
156+ self . trailing = trailing
171157 }
172-
158+
159+ // With track count only, no sort options, no trailing
173160 init (
174161 title: String ,
175162 subtitle: String ? = nil ,
176- sortOrder: Binding < [ KeyPathComparator < Track > ] > ,
177- tableRowSize: Binding < TableRowSize >
178- ) where TrailingContent == EmptyView {
163+ trackCount: Int
164+ ) where Trailing == EmptyView {
179165 self . title = title
180166 self . subtitle = subtitle
181- self . _sortOrder = sortOrder
182- self . _tableRowSize = tableRowSize
183- self . trailingContent = EmptyView ( )
167+ self . trackCount = trackCount
168+ self . sortOrder = nil
169+ self . tableRowSize = nil
170+ self . trailing = nil
184171 }
185172
186173 var body : some View {
187- ListHeader {
174+ ListHeader ( opaque : true ) {
188175 VStack ( alignment: . leading, spacing: 2 ) {
189176 Text ( title)
190177 . headerTitleStyle ( )
@@ -196,13 +183,20 @@ struct TrackListHeaderWithOptions<TrailingContent: View>: View {
196183 }
197184
198185 Spacer ( )
199-
200- trailingContent
201186
202- TrackTableOptionsDropdown (
203- sortOrder: $sortOrder,
204- tableRowSize: $tableRowSize
205- )
187+ if let trailing = trailing {
188+ trailing ( )
189+ } else if let trackCount = trackCount {
190+ Text ( " \( trackCount) tracks " )
191+ . headerSubtitleStyle ( )
192+ }
193+
194+ if let sortOrder = sortOrder, let tableRowSize = tableRowSize {
195+ TrackTableOptionsDropdown (
196+ sortOrder: sortOrder,
197+ tableRowSize: tableRowSize
198+ )
199+ }
206200 }
207201 }
208202}
0 commit comments