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

Compare commits

...

2 Commits

Author SHA1 Message Date
bc84d925d6
Less confusing 2019-03-08 16:02:36 -05:00
04a5eb1735
Maintain relative scroll position on resize 2019-03-08 15:52:01 -05:00
3 changed files with 26 additions and 1 deletions

View File

@ -44,6 +44,15 @@ class AlbumViewController: NSViewController,
albumCollectionView.collectionViewLayout?.invalidateLayout() albumCollectionView.collectionViewLayout?.invalidateLayout()
} }
override func viewDidLayout() {
super.viewDidLayout()
guard let layout = albumCollectionView.collectionViewLayout as? AlbumViewLayout
else { return }
layout.setScrollPosition()
}
@objc func updateAlbums(_ notification: Notification) { @objc func updateAlbums(_ notification: Notification) {
guard let albums = notification.userInfo?[Notification.albumsKey] as? [MPDClient.Album] guard let albums = notification.userInfo?[Notification.albumsKey] as? [MPDClient.Album]
else { return } else { return }

View File

@ -11,6 +11,7 @@ import Cocoa
class AlbumViewLayout: NSCollectionViewFlowLayout { class AlbumViewLayout: NSCollectionViewFlowLayout {
let maxItemWidth: CGFloat = 180 let maxItemWidth: CGFloat = 180
let albumInfoHeight: CGFloat = 39 let albumInfoHeight: CGFloat = 39
var scrollPosition: CGFloat = 0
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
super.init() super.init()
@ -35,6 +36,10 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
var divider: CGFloat = 1 var divider: CGFloat = 1
var itemWidth: CGFloat = 0 var itemWidth: CGFloat = 0
if let scrollView = collectionView.enclosingScrollView {
scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height
}
repeat { repeat {
let totalPaddingWidth = sectionInset.left + sectionInset.right let totalPaddingWidth = sectionInset.left + sectionInset.right
let totalGutterWidth = (divider - 1) * (minimumInteritemSpacing) let totalGutterWidth = (divider - 1) * (minimumInteritemSpacing)
@ -46,4 +51,11 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
itemSize = NSSize(width: itemWidth, height: itemHeight) itemSize = NSSize(width: itemWidth, height: itemHeight)
} }
func setScrollPosition() {
guard let collectionView = collectionView
else { return }
collectionView.scroll(NSPoint(x: 0, y: scrollPosition * collectionView.bounds.height))
}
} }

View File

@ -43,7 +43,7 @@ class AlbumItemView: NSView {
NotificationCenter.default.addObserver( NotificationCenter.default.addObserver(
self, self,
selector: #selector(viewWillScroll(_:)), selector: #selector(viewDidScroll(_:)),
name: NSScrollView.didLiveScrollNotification, name: NSScrollView.didLiveScrollNotification,
object: nil object: nil
) )
@ -59,6 +59,10 @@ class AlbumItemView: NSView {
hidePlayButton() hidePlayButton()
} }
@objc func viewDidScroll(_ notification: Notification) {
hidePlayButton()
}
override func resize(withOldSuperviewSize oldSize: NSSize) { override func resize(withOldSuperviewSize oldSize: NSSize) {
hidePlayButton() hidePlayButton()
} }