|
|
@@ -7,6 +7,12 @@ import Cocoa
|
|
7
|
7
|
|
|
8
|
8
|
class ViewController: NSViewController {
|
|
9
|
9
|
|
|
|
10
|
+ private var sidebar: SidebarView!
|
|
|
11
|
+ private var homeContentView: NSView!
|
|
|
12
|
+ private var scanContentView: NSView!
|
|
|
13
|
+ private var scanAndHomeContentView: NSView!
|
|
|
14
|
+ private var contentContainer: NSView!
|
|
|
15
|
+
|
|
10
|
16
|
override func loadView() {
|
|
11
|
17
|
let container = NSView(frame: NSRect(x: 0, y: 0, width: AppTheme.windowWidth, height: AppTheme.windowHeight))
|
|
12
|
18
|
container.autoresizingMask = [.width, .height]
|
|
|
@@ -21,7 +27,7 @@ class ViewController: NSViewController {
|
|
21
|
27
|
}
|
|
22
|
28
|
|
|
23
|
29
|
private func setupLayout() {
|
|
24
|
|
- let sidebar = SidebarView()
|
|
|
30
|
+ sidebar = SidebarView()
|
|
25
|
31
|
|
|
26
|
32
|
let mainContent = NSView()
|
|
27
|
33
|
mainContent.translatesAutoresizingMaskIntoConstraints = false
|
|
|
@@ -29,7 +35,17 @@ class ViewController: NSViewController {
|
|
29
|
35
|
mainContent.layer?.backgroundColor = AppTheme.background.cgColor
|
|
30
|
36
|
|
|
31
|
37
|
let header = makeHeader()
|
|
32
|
|
- let scrollView = makeScrollView()
|
|
|
38
|
+
|
|
|
39
|
+ contentContainer = NSView()
|
|
|
40
|
+ contentContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
41
|
+
|
|
|
42
|
+ homeContentView = makeHomeContentView()
|
|
|
43
|
+ scanContentView = makeScanContentView()
|
|
|
44
|
+ scanAndHomeContentView = makeScanAndHomeContentView()
|
|
|
45
|
+
|
|
|
46
|
+ contentContainer.addSubview(homeContentView)
|
|
|
47
|
+ contentContainer.addSubview(scanContentView)
|
|
|
48
|
+ contentContainer.addSubview(scanAndHomeContentView)
|
|
33
|
49
|
|
|
34
|
50
|
let wavePattern = WavePatternView()
|
|
35
|
51
|
wavePattern.translatesAutoresizingMaskIntoConstraints = false
|
|
|
@@ -37,9 +53,13 @@ class ViewController: NSViewController {
|
|
37
|
53
|
view.addSubview(sidebar)
|
|
38
|
54
|
view.addSubview(mainContent)
|
|
39
|
55
|
mainContent.addSubview(header)
|
|
40
|
|
- mainContent.addSubview(scrollView)
|
|
|
56
|
+ mainContent.addSubview(contentContainer)
|
|
41
|
57
|
mainContent.addSubview(wavePattern)
|
|
42
|
58
|
|
|
|
59
|
+ sidebar.onDestinationSelected = { [weak self] destination in
|
|
|
60
|
+ self?.showDestination(destination)
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
43
|
63
|
NSLayoutConstraint.activate([
|
|
44
|
64
|
sidebar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
45
|
65
|
sidebar.topAnchor.constraint(equalTo: view.topAnchor),
|
|
|
@@ -55,16 +75,125 @@ class ViewController: NSViewController {
|
|
55
|
75
|
header.topAnchor.constraint(equalTo: mainContent.topAnchor, constant: 16),
|
|
56
|
76
|
header.heightAnchor.constraint(equalToConstant: 44),
|
|
57
|
77
|
|
|
58
|
|
- scrollView.leadingAnchor.constraint(equalTo: mainContent.leadingAnchor),
|
|
59
|
|
- scrollView.trailingAnchor.constraint(equalTo: mainContent.trailingAnchor),
|
|
60
|
|
- scrollView.topAnchor.constraint(equalTo: header.bottomAnchor, constant: 8),
|
|
61
|
|
- scrollView.bottomAnchor.constraint(equalTo: mainContent.bottomAnchor),
|
|
|
78
|
+ contentContainer.leadingAnchor.constraint(equalTo: mainContent.leadingAnchor),
|
|
|
79
|
+ contentContainer.trailingAnchor.constraint(equalTo: mainContent.trailingAnchor),
|
|
|
80
|
+ contentContainer.topAnchor.constraint(equalTo: header.bottomAnchor, constant: 8),
|
|
|
81
|
+ contentContainer.bottomAnchor.constraint(equalTo: mainContent.bottomAnchor),
|
|
62
|
82
|
|
|
63
|
83
|
wavePattern.trailingAnchor.constraint(equalTo: mainContent.trailingAnchor),
|
|
64
|
84
|
wavePattern.bottomAnchor.constraint(equalTo: mainContent.bottomAnchor),
|
|
65
|
85
|
wavePattern.widthAnchor.constraint(equalToConstant: 200),
|
|
66
|
86
|
wavePattern.heightAnchor.constraint(equalToConstant: 140),
|
|
67
|
87
|
])
|
|
|
88
|
+
|
|
|
89
|
+ pinContentView(homeContentView)
|
|
|
90
|
+ pinContentView(scanContentView)
|
|
|
91
|
+ pinContentView(scanAndHomeContentView)
|
|
|
92
|
+ showDestination(.home)
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ private func pinContentView(_ contentView: NSView) {
|
|
|
96
|
+ NSLayoutConstraint.activate([
|
|
|
97
|
+ contentView.leadingAnchor.constraint(equalTo: contentContainer.leadingAnchor),
|
|
|
98
|
+ contentView.trailingAnchor.constraint(equalTo: contentContainer.trailingAnchor),
|
|
|
99
|
+ contentView.topAnchor.constraint(equalTo: contentContainer.topAnchor),
|
|
|
100
|
+ contentView.bottomAnchor.constraint(equalTo: contentContainer.bottomAnchor),
|
|
|
101
|
+ ])
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ private func showDestination(_ destination: SidebarDestination) {
|
|
|
105
|
+ homeContentView.isHidden = destination != .home
|
|
|
106
|
+ scanContentView.isHidden = destination != .scan
|
|
|
107
|
+ scanAndHomeContentView.isHidden = destination != .scanAndHome
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ private func makeHomeContentView() -> NSView {
|
|
|
111
|
+ let container = NSView()
|
|
|
112
|
+ container.translatesAutoresizingMaskIntoConstraints = false
|
|
|
113
|
+
|
|
|
114
|
+ let scrollView = makeScrollView()
|
|
|
115
|
+ container.addSubview(scrollView)
|
|
|
116
|
+
|
|
|
117
|
+ NSLayoutConstraint.activate([
|
|
|
118
|
+ scrollView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
|
119
|
+ scrollView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
|
120
|
+ scrollView.topAnchor.constraint(equalTo: container.topAnchor),
|
|
|
121
|
+ scrollView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
|
|
|
122
|
+ ])
|
|
|
123
|
+
|
|
|
124
|
+ return container
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ private func makeScanContentView() -> NSView {
|
|
|
128
|
+ makeDestinationScrollView(
|
|
|
129
|
+ title: "Scan",
|
|
|
130
|
+ features: [
|
|
|
131
|
+ FeatureCardData(title: "Scan File", subtitle: "Scan any document", iconKind: .scanFile),
|
|
|
132
|
+ FeatureCardData(title: "OCR File", subtitle: "Scan and print text from images", iconKind: .ocrFile),
|
|
|
133
|
+ ]
|
|
|
134
|
+ )
|
|
|
135
|
+ }
|
|
|
136
|
+
|
|
|
137
|
+ private func makeScanAndHomeContentView() -> NSView {
|
|
|
138
|
+ makeDestinationScrollView(
|
|
|
139
|
+ title: "Premium",
|
|
|
140
|
+ features: [
|
|
|
141
|
+ FeatureCardData(title: "From Photos", subtitle: "Take a photo from gallery", iconKind: .scanFile),
|
|
|
142
|
+ FeatureCardData(title: "Scan File", subtitle: "Scan any document", iconKind: .scanFile),
|
|
|
143
|
+ FeatureCardData(title: "Print Text", subtitle: "Type text and print", iconKind: .printText),
|
|
|
144
|
+ FeatureCardData(title: "Print Contacts", subtitle: "Print your contacts", iconKind: .printContacts),
|
|
|
145
|
+ ]
|
|
|
146
|
+ )
|
|
|
147
|
+ }
|
|
|
148
|
+
|
|
|
149
|
+ private func makeDestinationScrollView(title: String, features: [FeatureCardData]) -> NSView {
|
|
|
150
|
+ let container = NSView()
|
|
|
151
|
+ container.translatesAutoresizingMaskIntoConstraints = false
|
|
|
152
|
+ container.isHidden = true
|
|
|
153
|
+
|
|
|
154
|
+ let scrollView = NSScrollView()
|
|
|
155
|
+ scrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
156
|
+ scrollView.hasVerticalScroller = true
|
|
|
157
|
+ scrollView.hasHorizontalScroller = false
|
|
|
158
|
+ scrollView.autohidesScrollers = true
|
|
|
159
|
+ scrollView.drawsBackground = false
|
|
|
160
|
+ scrollView.borderType = .noBorder
|
|
|
161
|
+
|
|
|
162
|
+ let documentView = FlippedDocumentView()
|
|
|
163
|
+ documentView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
164
|
+
|
|
|
165
|
+ let sectionTitle = makeSectionTitle(title, showGridIcon: true)
|
|
|
166
|
+ let grid = makeFeatureRow(features: features)
|
|
|
167
|
+
|
|
|
168
|
+ documentView.addSubview(sectionTitle)
|
|
|
169
|
+ documentView.addSubview(grid)
|
|
|
170
|
+ scrollView.documentView = documentView
|
|
|
171
|
+ container.addSubview(scrollView)
|
|
|
172
|
+
|
|
|
173
|
+ let contentGuide = scrollView.contentView
|
|
|
174
|
+
|
|
|
175
|
+ NSLayoutConstraint.activate([
|
|
|
176
|
+ scrollView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
|
177
|
+ scrollView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
|
178
|
+ scrollView.topAnchor.constraint(equalTo: container.topAnchor),
|
|
|
179
|
+ scrollView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
|
|
|
180
|
+
|
|
|
181
|
+ documentView.topAnchor.constraint(equalTo: contentGuide.topAnchor),
|
|
|
182
|
+ documentView.leadingAnchor.constraint(equalTo: contentGuide.leadingAnchor),
|
|
|
183
|
+ documentView.trailingAnchor.constraint(equalTo: contentGuide.trailingAnchor),
|
|
|
184
|
+ documentView.widthAnchor.constraint(equalTo: contentGuide.widthAnchor),
|
|
|
185
|
+
|
|
|
186
|
+ sectionTitle.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: AppTheme.contentPadding),
|
|
|
187
|
+ sectionTitle.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -AppTheme.contentPadding),
|
|
|
188
|
+ sectionTitle.topAnchor.constraint(equalTo: documentView.topAnchor, constant: 8),
|
|
|
189
|
+
|
|
|
190
|
+ grid.leadingAnchor.constraint(equalTo: documentView.leadingAnchor, constant: AppTheme.contentPadding),
|
|
|
191
|
+ grid.trailingAnchor.constraint(equalTo: documentView.trailingAnchor, constant: -AppTheme.contentPadding),
|
|
|
192
|
+ grid.topAnchor.constraint(equalTo: sectionTitle.bottomAnchor, constant: 16),
|
|
|
193
|
+ grid.bottomAnchor.constraint(equalTo: documentView.bottomAnchor, constant: -40),
|
|
|
194
|
+ ])
|
|
|
195
|
+
|
|
|
196
|
+ return container
|
|
68
|
197
|
}
|
|
69
|
198
|
|
|
70
|
199
|
private func makeHeader() -> NSView {
|