7
7
8
8
import AppKit
9
9
import AdvancedCollectionTableView
10
+ import FZSwiftUtils
11
+ import FZUIKit
10
12
11
13
class MainViewController : NSViewController {
12
14
typealias DataSource = CollectionViewDiffableDataSource < Section , GalleryItem >
@@ -47,9 +49,56 @@ class MainViewController: NSViewController {
47
49
}
48
50
}
49
51
52
+ let testView = TestView ( )
53
+ let view1 = TestView ( )
54
+ let view2 = TestView ( )
50
55
override func viewDidLoad( ) {
51
56
super. viewDidLoad ( )
52
57
58
+
59
+ Swift . print ( " view1 " , view1. tag)
60
+ Swift . print ( " view2 " , view2. tag)
61
+
62
+ Swift . print ( " ----- " )
63
+ testView. addSubview ( view1)
64
+ Swift . print ( " ----- " )
65
+ testView. addSubview ( view2)
66
+ Swift . print ( " ----- " )
67
+ testView. addSubview ( view1)
68
+ Swift . print ( " ----- " )
69
+ testView. subviews = [ view1, view2]
70
+ Swift . print ( " ----- " )
71
+ testView. subviews = [ view2, view1]
72
+ Swift . print ( " ----- " )
73
+ testView. subviews = [ view2]
74
+
75
+
76
+ var configuration = NSListContentConfiguration . sidebar ( )
77
+ configuration. text = LoremIpsum . words ( 3 )
78
+ configuration. secondaryText = LoremIpsum . words ( 6 )
79
+ configuration. secondaryTextProperties. maximumNumberOfLines = 0
80
+ configuration. image = NSImage ( systemSymbolName: " photo " )
81
+ let contentView = configuration. makeContentView ( )
82
+ contentView. frame. size = contentView. systemLayoutSizeFitting ( width: 400 )
83
+ let containerView = NSTableCellView ( )
84
+ containerView. frame. origin = CGPoint ( 20 )
85
+ containerView. frame. size = contentView. frame. size
86
+
87
+ containerView. addSubview ( contentView)
88
+ containerView. cornerRadius = contentView. frame. size. height / 2.0
89
+ Swift . print ( contentView. frame. size. height / 2.0 )
90
+ contentView. frame. origin. x = contentView. frame. size. height / 2.0
91
+ containerView. backgroundColor = . controlAccentColor
92
+ containerView. backgroundStyle = . emphasized
93
+ // view.addSubview(containerView)
94
+
95
+ let maskView = MaskView ( ) . size ( CGSize ( 120 , 60 ) )
96
+ maskView. backgroundColor = . clear
97
+ maskView. shadowPath = . init( rect: maskView. bounds)
98
+ view. addSubview ( maskView)
99
+ // maskView.configurate(using: ShapeConfiguration.capsule)
100
+ maskView. outerShadow = . accentColor( opacity: 0.9 )
101
+
53
102
collectionView. collectionViewLayout = . grid( columns: 3 )
54
103
collectionView. dataSource = dataSource
55
104
@@ -87,6 +136,28 @@ class MainViewController: NSViewController {
87
136
}
88
137
}
89
138
139
+ class MaskView : NSView {
140
+ let shapeLayer = CAShapeLayer ( )
141
+
142
+ override func layout( ) {
143
+ super. layout ( )
144
+
145
+ shapeLayer. frame = bounds
146
+ shapeLayer. path = NSBezierPath ( roundedRect: bounds, cornerRadius: bounds. height/ 2.0 ) . cgPath
147
+ }
148
+
149
+ override init ( frame frameRect: NSRect ) {
150
+ super. init ( frame: frameRect)
151
+ wantsLayer = true
152
+ // layer?.addSublayer(shapeLayer)
153
+ shapeLayer. fillColor = NSColor . controlAccentColor. cgColor
154
+ }
155
+
156
+ required init ? ( coder: NSCoder ) {
157
+ super. init ( coder: coder)
158
+ }
159
+ }
160
+
90
161
private extension NSView {
91
162
/// Creates a colored view.
92
163
convenience init ( color: NSColor , opacity: CGFloat ) {
@@ -95,3 +166,40 @@ private extension NSView {
95
166
alphaValue = opacity
96
167
}
97
168
}
169
+
170
+
171
+
172
+ class TestView : NSView {
173
+ var _tag : Int = Int . random ( max: 30 )
174
+
175
+ override var tag : Int {
176
+ _tag
177
+ }
178
+
179
+ override func layout( ) {
180
+ super. layout ( )
181
+ Swift . print ( " layout " )
182
+ }
183
+
184
+ override func viewDidMoveToSuperview( ) {
185
+ Swift . print ( " superview viewDidMoveToSuperview " , superview != nil )
186
+ }
187
+
188
+ override func viewWillMove( toSuperview newSuperview: NSView ? ) {
189
+ Swift . print ( " superview viewWillMove " , newSuperview != nil )
190
+ }
191
+
192
+ override func layoutSubtreeIfNeeded( ) {
193
+ Swift . print ( " layoutSubtreeIfNeeded " )
194
+ }
195
+
196
+ override func willRemoveSubview( _ subview: NSView ) {
197
+ Swift . print ( " willRemoveSubview " , subview. tag)
198
+
199
+ }
200
+
201
+ override func didAddSubview( _ subview: NSView ) {
202
+ Swift . print ( " didAddSubview " , subview. tag)
203
+ }
204
+ }
205
+
0 commit comments