1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Better borders

The original border was not following the curve of the album cover
corners. Changing the background of the background box too fills in
these little gaps and makes the selection look cleaner.
This commit is contained in:
Daniel Barber 2019-11-01 13:38:58 -04:00
parent da851365d6
commit 47ad36f12a
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -14,7 +14,7 @@ class AlbumViewItem: NSCollectionViewItem {
override var isSelected: Bool { override var isSelected: Bool {
didSet { didSet {
albumCoverBox.layer?.borderWidth = isSelected ? 5 : 0 setAppearance(selected: isSelected)
} }
} }
@ -28,14 +28,14 @@ class AlbumViewItem: NSCollectionViewItem {
albumCoverView.layer?.masksToBounds = true albumCoverView.layer?.masksToBounds = true
albumCoverBox.wantsLayer = true albumCoverBox.wantsLayer = true
albumCoverBox.layer?.cornerRadius = 5 albumCoverBox.layer?.cornerRadius = 6
albumCoverBox.layer?.borderWidth = 0 albumCoverBox.layer?.borderWidth = 5
setAppearance() setAppearance(selected: false)
if #available(OSX 10.14, *) { if #available(OSX 10.14, *) {
observer = NSApp.observe(\.effectiveAppearance) { (app, _) in observer = NSApp.observe(\.effectiveAppearance) { (app, _) in
self.setAppearance() self.setAppearance(selected: false)
} }
} }
} }
@ -59,16 +59,18 @@ class AlbumViewItem: NSCollectionViewItem {
} }
} }
func setAppearance() { func setAppearance(selected isSelected: Bool) {
if #available(OSX 10.14, *) { if #available(OSX 10.14, *) {
let darkMode = NSApp.effectiveAppearance.bestMatch(from: let darkMode = NSApp.effectiveAppearance.bestMatch(from:
[.darkAqua, .aqua]) == .darkAqua [.darkAqua, .aqua]) == .darkAqua
albumCoverView.layer?.borderColor = darkMode ? .albumBorderColorDark : .albumBorderColorLight albumCoverView.layer?.borderColor = darkMode ? .albumBorderColorDark : .albumBorderColorLight
albumCoverBox.layer?.borderColor = NSColor.controlAccentColor.cgColor albumCoverBox.layer?.borderColor = isSelected ? NSColor.controlAccentColor.cgColor : CGColor.clear
albumCoverBox.layer?.backgroundColor = isSelected ? NSColor.controlAccentColor.cgColor : CGColor.clear
} else { } else {
albumCoverView.layer?.borderColor = .albumBorderColorLight albumCoverView.layer?.borderColor = .albumBorderColorLight
albumCoverBox.layer?.borderColor = NSColor.selectedControlColor.cgColor albumCoverBox.layer?.borderColor = isSelected ? NSColor.selectedControlColor.cgColor : CGColor.clear
albumCoverBox.layer?.backgroundColor = isSelected ? NSColor.selectedControlColor.cgColor : CGColor.clear
} }
} }