@@ -23,15 +23,23 @@ open class STCompletionViewController: NSViewController, STCompletionViewControl
23
23
view = NSView ( )
24
24
view. translatesAutoresizingMaskIntoConstraints = false
25
25
view. wantsLayer = true
26
- view. layer? . cornerRadius = 5
27
- view. layer? . backgroundColor = NSColor . windowBackgroundColor . cgColor
26
+ view. layer? . cornerRadius = 8
27
+ view. layer? . cornerCurve = . continuous
28
28
29
29
NSLayoutConstraint . activate (
30
30
[
31
31
view. widthAnchor. constraint ( greaterThanOrEqualToConstant: 320 )
32
32
]
33
33
)
34
34
35
+ let backgroundEffect = NSVisualEffectView ( frame: view. bounds)
36
+ backgroundEffect. autoresizingMask = [ . width, . height]
37
+ backgroundEffect. blendingMode = . withinWindow
38
+ backgroundEffect. material = . windowBackground
39
+ backgroundEffect. state = . followsWindowActiveState
40
+ backgroundEffect. wantsLayer = true
41
+ view. addSubview ( backgroundEffect)
42
+
35
43
tableView. style = . plain
36
44
tableView. translatesAutoresizingMaskIntoConstraints = false
37
45
tableView. headerView = nil
@@ -61,7 +69,7 @@ open class STCompletionViewController: NSViewController, STCompletionViewControl
61
69
let scrollView = NSScrollView ( )
62
70
scrollView. translatesAutoresizingMaskIntoConstraints = false
63
71
scrollView. automaticallyAdjustsContentInsets = false
64
- scrollView. contentInsets = NSEdgeInsets ( top: 4 , left: 4 , bottom: 4 , right: 4 )
72
+ scrollView. contentInsets = NSEdgeInsets ( top: 6 , left: 6 , bottom: 6 , right: 6 )
65
73
scrollView. drawsBackground = false
66
74
scrollView. backgroundColor = . clear
67
75
scrollView. borderType = . noBorder
@@ -179,7 +187,7 @@ extension STCompletionViewController: NSTableViewDelegate {
179
187
}
180
188
181
189
open func tableView( _ tableView: NSTableView , rowViewForRow row: Int ) -> NSTableRowView ? {
182
- STTableRowView ( )
190
+ STTableRowView ( parentCornerRadius : view . layer! . cornerRadius , inset : tableView . enclosingScrollView ? . contentInsets . top ?? 0 )
183
191
}
184
192
185
193
}
@@ -192,13 +200,31 @@ extension STCompletionViewController: NSTableViewDataSource {
192
200
193
201
private class STTableRowView : NSTableRowView {
194
202
203
+ private let parentCornerRadius : CGFloat
204
+ private let inset : CGFloat
205
+
206
+ init ( parentCornerRadius: CGFloat , inset: CGFloat ) {
207
+ self . parentCornerRadius = parentCornerRadius * 2
208
+ self . inset = inset
209
+ super. init ( frame: . zero)
210
+ }
211
+
212
+ required init ? ( coder: NSCoder ) {
213
+ fatalError ( " init(coder:) has not been implemented " )
214
+ }
215
+
195
216
override func drawSelection( in dirtyRect: NSRect ) {
196
217
guard let context = NSGraphicsContext . current? . cgContext else { return }
197
- context. saveGState ( )
198
- let path = NSBezierPath ( roundedRect: dirtyRect, xRadius: 4 , yRadius: 4 )
199
- context. setFillColor ( NSColor . controlAccentColor. withAlphaComponent ( 0.7 ) . cgColor)
200
- path. fill ( )
201
- context. restoreGState ( )
218
+ if isSelected {
219
+ context. saveGState ( )
220
+ let isDark = effectiveAppearance. bestMatch ( from: [ . darkAqua, . aqua] ) == . darkAqua
221
+
222
+ let radius = ( parentCornerRadius - inset) / 2
223
+ let path = NSBezierPath ( roundedRect: bounds, xRadius: radius, yRadius: radius)
224
+ context. setFillColor ( NSColor . white. withAlphaComponent ( isDark ? 0.2 : 1 ) . cgColor)
225
+ path. fill ( )
226
+ context. restoreGState ( )
227
+ }
202
228
}
203
229
}
204
230
0 commit comments