mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Compare commits
2 Commits
92366ac795
...
bc84d925d6
| Author | SHA1 | Date | |
|---|---|---|---|
| bc84d925d6 | |||
| 04a5eb1735 |
@ -44,6 +44,15 @@ class AlbumViewController: NSViewController,
|
||||
albumCollectionView.collectionViewLayout?.invalidateLayout()
|
||||
}
|
||||
|
||||
override func viewDidLayout() {
|
||||
super.viewDidLayout()
|
||||
|
||||
guard let layout = albumCollectionView.collectionViewLayout as? AlbumViewLayout
|
||||
else { return }
|
||||
|
||||
layout.setScrollPosition()
|
||||
}
|
||||
|
||||
@objc func updateAlbums(_ notification: Notification) {
|
||||
guard let albums = notification.userInfo?[Notification.albumsKey] as? [MPDClient.Album]
|
||||
else { return }
|
||||
|
||||
@ -11,6 +11,7 @@ import Cocoa
|
||||
class AlbumViewLayout: NSCollectionViewFlowLayout {
|
||||
let maxItemWidth: CGFloat = 180
|
||||
let albumInfoHeight: CGFloat = 39
|
||||
var scrollPosition: CGFloat = 0
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init()
|
||||
@ -35,6 +36,10 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
|
||||
var divider: CGFloat = 1
|
||||
var itemWidth: CGFloat = 0
|
||||
|
||||
if let scrollView = collectionView.enclosingScrollView {
|
||||
scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height
|
||||
}
|
||||
|
||||
repeat {
|
||||
let totalPaddingWidth = sectionInset.left + sectionInset.right
|
||||
let totalGutterWidth = (divider - 1) * (minimumInteritemSpacing)
|
||||
@ -46,4 +51,11 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
|
||||
|
||||
itemSize = NSSize(width: itemWidth, height: itemHeight)
|
||||
}
|
||||
|
||||
func setScrollPosition() {
|
||||
guard let collectionView = collectionView
|
||||
else { return }
|
||||
|
||||
collectionView.scroll(NSPoint(x: 0, y: scrollPosition * collectionView.bounds.height))
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class AlbumItemView: NSView {
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(viewWillScroll(_:)),
|
||||
selector: #selector(viewDidScroll(_:)),
|
||||
name: NSScrollView.didLiveScrollNotification,
|
||||
object: nil
|
||||
)
|
||||
@ -59,6 +59,10 @@ class AlbumItemView: NSView {
|
||||
hidePlayButton()
|
||||
}
|
||||
|
||||
@objc func viewDidScroll(_ notification: Notification) {
|
||||
hidePlayButton()
|
||||
}
|
||||
|
||||
override func resize(withOldSuperviewSize oldSize: NSSize) {
|
||||
hidePlayButton()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user