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()
}
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 }

View File

@ -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))
}
}

View File

@ -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()
}