|
|
@@ -199,7 +199,7 @@ class ViewController: NSViewController {
|
|
199
|
199
|
documentView.translatesAutoresizingMaskIntoConstraints = false
|
|
200
|
200
|
|
|
201
|
201
|
let sectionTitle = makeSectionTitle(title, icon: .grid)
|
|
202
|
|
- let grid = makeFeatureRow(features: features)
|
|
|
202
|
+ let grid = makeFeatureGrid(features: features, columns: AppTheme.featureGridColumns)
|
|
203
|
203
|
|
|
204
|
204
|
documentView.addSubview(sectionTitle)
|
|
205
|
205
|
documentView.addSubview(grid)
|
|
|
@@ -436,19 +436,12 @@ class ViewController: NSViewController {
|
|
436
|
436
|
FeatureCardData(title: "Scan File", subtitle: "Scan any document", iconKind: .scanFile),
|
|
437
|
437
|
FeatureCardData(title: "Print Text", subtitle: "Type text and print", iconKind: .printText),
|
|
438
|
438
|
FeatureCardData(title: "Print Contacts", subtitle: "Print your contacts", iconKind: .printContacts),
|
|
439
|
|
- FeatureCardData(title: "Print Website", subtitle: "Print any website", iconKind: .printWebsite),
|
|
440
|
439
|
FeatureCardData(title: "Draw & Print", subtitle: "Add drawings, text and more", iconKind: .drawPrint),
|
|
441
|
440
|
FeatureCardData(title: "OCR File", subtitle: "Scan and print text from images", iconKind: .ocrFile),
|
|
|
441
|
+ FeatureCardData(title: "Print Website", subtitle: "Print any website", iconKind: .printWebsite),
|
|
442
|
442
|
]
|
|
443
|
443
|
|
|
444
|
|
- let topRow = makeFeatureRow(features: Array(features.prefix(4)))
|
|
445
|
|
- let bottomRow = makeFeatureRow(features: Array(features.suffix(2)))
|
|
446
|
|
-
|
|
447
|
|
- let grid = NSStackView(views: [topRow, bottomRow])
|
|
448
|
|
- grid.orientation = .vertical
|
|
449
|
|
- grid.spacing = AppTheme.featureGridSpacing
|
|
450
|
|
- grid.distribution = .fillEqually
|
|
451
|
|
- grid.translatesAutoresizingMaskIntoConstraints = false
|
|
|
444
|
+ let grid = makeFeatureGrid(features: features, columns: AppTheme.featureGridColumns)
|
|
452
|
445
|
|
|
453
|
446
|
section.addSubview(grid)
|
|
454
|
447
|
|
|
|
@@ -465,18 +458,40 @@ class ViewController: NSViewController {
|
|
465
|
458
|
return section
|
|
466
|
459
|
}
|
|
467
|
460
|
|
|
468
|
|
- private func makeFeatureRow(features: [FeatureCardData]) -> NSStackView {
|
|
469
|
|
- let row = NSStackView()
|
|
470
|
|
- row.orientation = .horizontal
|
|
471
|
|
- row.spacing = AppTheme.featureGridSpacing
|
|
472
|
|
- row.distribution = .fillEqually
|
|
473
|
|
- row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
461
|
+ private func makeFeatureGrid(features: [FeatureCardData], columns: Int) -> NSView {
|
|
|
462
|
+ let grid = NSStackView()
|
|
|
463
|
+ grid.orientation = .vertical
|
|
|
464
|
+ grid.spacing = AppTheme.featureGridSpacing
|
|
|
465
|
+ grid.distribution = .fill
|
|
|
466
|
+ grid.alignment = .leading
|
|
|
467
|
+ grid.translatesAutoresizingMaskIntoConstraints = false
|
|
|
468
|
+
|
|
|
469
|
+ var index = 0
|
|
|
470
|
+ while index < features.count {
|
|
|
471
|
+ let row = NSStackView()
|
|
|
472
|
+ row.orientation = .horizontal
|
|
|
473
|
+ row.spacing = AppTheme.featureGridSpacing
|
|
|
474
|
+ row.distribution = .fillEqually
|
|
|
475
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
476
|
+
|
|
|
477
|
+ let rowCount = min(columns, features.count - index)
|
|
|
478
|
+ for offset in 0..<rowCount {
|
|
|
479
|
+ row.addArrangedSubview(FeatureCardView(data: features[index + offset]))
|
|
|
480
|
+ }
|
|
|
481
|
+ for _ in 0..<(columns - rowCount) {
|
|
|
482
|
+ let spacer = NSView()
|
|
|
483
|
+ spacer.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
|
484
|
+ spacer.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
|
485
|
+ row.addArrangedSubview(spacer)
|
|
|
486
|
+ }
|
|
474
|
487
|
|
|
475
|
|
- for data in features {
|
|
476
|
|
- row.addArrangedSubview(FeatureCardView(data: data))
|
|
|
488
|
+ grid.addArrangedSubview(row)
|
|
|
489
|
+ row.leadingAnchor.constraint(equalTo: grid.leadingAnchor).isActive = true
|
|
|
490
|
+ row.trailingAnchor.constraint(equalTo: grid.trailingAnchor).isActive = true
|
|
|
491
|
+ index += rowCount
|
|
477
|
492
|
}
|
|
478
|
493
|
|
|
479
|
|
- return row
|
|
|
494
|
+ return grid
|
|
480
|
495
|
}
|
|
481
|
496
|
}
|
|
482
|
497
|
|