2
2
// https://github.com/krzyzanowskim/STTextView/blob/main/LICENSE.md
3
3
//
4
4
// STGutterView
5
+ // |- NSVisualEffectView
5
6
// |- STGutterContainerView
7
+ // |- STGutterSeparatorView
6
8
// |-STGutterLineNumberCell
7
9
// |- STGutterMarkerContainerView
8
10
// |-STGutterMarker.view
@@ -27,6 +29,7 @@ public extension STGutterViewDelegate {
27
29
28
30
/// A gutter to the side of a scroll view’s document view.
29
31
open class STGutterView : NSView , NSDraggingSource {
32
+ internal let separatorView : STGutterSeparatorView
30
33
internal let containerView : STGutterContainerView
31
34
internal let markerContainerView : STGutterMarkerContainerView
32
35
@@ -53,8 +56,14 @@ open class STGutterView: NSView, NSDraggingSource {
53
56
open var textColor = NSColor . secondaryLabelColor
54
57
55
58
/// A Boolean indicating whether to draw a separator or not. Default true.
56
- @Invalidating ( . display)
57
- open var drawSeparator : Bool = true
59
+ open var drawSeparator : Bool {
60
+ get {
61
+ separatorView. drawSeparator
62
+ }
63
+ set {
64
+ separatorView. drawSeparator = newValue
65
+ }
66
+ }
58
67
59
68
/// A Boolean that controls whether the text view highlights the currently selected line. Default false.
60
69
@Invalidating ( . display)
@@ -70,7 +79,8 @@ open class STGutterView: NSView, NSDraggingSource {
70
79
backgroundEffect. blendingMode = . withinWindow
71
80
backgroundEffect. material = . contentBackground
72
81
backgroundEffect. state = . followsWindowActiveState
73
- addSubview ( backgroundEffect, positioned: . below, relativeTo: self )
82
+ // insert subview to `self`. below other subviews.
83
+ self . subviews. insert ( backgroundEffect, at: 0 )
74
84
self . _backgroundEffectView = backgroundEffect
75
85
} else if backgroundColor != nil , _backgroundEffectView != nil {
76
86
_backgroundEffectView? . removeFromSuperview ( )
@@ -90,8 +100,14 @@ open class STGutterView: NSView, NSDraggingSource {
90
100
/// The color of the separator.
91
101
///
92
102
/// Needs ``drawSeparator`` to be set to `true`.
93
- @Invalidating ( . display)
94
- open var separatorColor = NSColor . separatorColor. withAlphaComponent ( 0.1 )
103
+ open var separatorColor : NSColor {
104
+ get {
105
+ separatorView. separatorColor
106
+ }
107
+ set {
108
+ separatorView. separatorColor = newValue
109
+ }
110
+ }
95
111
96
112
/// The receiver’s gutter markers to markers, removing any existing ruler markers and not consulting with the client view about the new markers.
97
113
@Invalidating ( . markers)
@@ -113,6 +129,9 @@ open class STGutterView: NSView, NSDraggingSource {
113
129
}
114
130
115
131
override init ( frame: CGRect ) {
132
+ separatorView = STGutterSeparatorView ( frame: frame)
133
+ separatorView. autoresizingMask = [ . width, . height]
134
+
116
135
containerView = STGutterContainerView ( frame: frame)
117
136
containerView. autoresizingMask = [ . width, . height]
118
137
@@ -123,6 +142,7 @@ open class STGutterView: NSView, NSDraggingSource {
123
142
wantsLayer = true
124
143
clipsToBounds = true
125
144
145
+ addSubview ( separatorView)
126
146
addSubview ( containerView)
127
147
addSubview ( markerContainerView)
128
148
@@ -185,21 +205,6 @@ open class STGutterView: NSView, NSDraggingSource {
185
205
}
186
206
}
187
207
188
- open override func draw( _ rect: CGRect ) {
189
- super. draw ( rect)
190
-
191
- guard let context = NSGraphicsContext . current? . cgContext else {
192
- return
193
- }
194
-
195
- if drawSeparator {
196
- context. setLineWidth ( 1 )
197
- context. setStrokeColor ( separatorColor. cgColor)
198
- context. addLines ( between: [ CGPoint ( x: frame. width - 0.5 , y: 0 ) , CGPoint ( x: frame. width - 0.5 , y: bounds. maxY) ] )
199
- context. strokePath ( )
200
- }
201
- }
202
-
203
208
open override func mouseDown( with event: NSEvent ) {
204
209
if areMarkersEnabled, event. type == . leftMouseDown, event. clickCount == 1 {
205
210
let eventPoint = containerView. convert ( event. locationInWindow, from: nil )
0 commit comments