1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00
persephone/Persephone/Views/AlbumItemView.swift
Dan Barber 2d6aa478a7
Add a button to albums that plays the album
This works by clearing the queue, adding all the tracks from the album
to the queue and playing the first track.

Fix bug where resize might leave a play button visible

Had to refactor the QueueView somewhat as there was a bug that only
surfaced on clearing and refilling the playlist. The bug was due to the
way NSOutlineView reuses subviews.

Add screenshot with album play button

Move queue datasource and refactor view controller

Move album datasource out of the view controller
2019-02-22 13:09:09 -05:00

72 lines
1.5 KiB
Swift

//
// AlbumItemView.swift
// Persephone
//
// Created by Daniel Barber on 2019/2/17.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Cocoa
class AlbumItemView: NSView {
var trackingArea: NSTrackingArea?
override func updateTrackingAreas() {
super.updateTrackingAreas()
guard let albumImageView = imageView else { return }
if let trackingArea = self.trackingArea {
self.removeTrackingArea(trackingArea)
}
let trackingArea = NSTrackingArea(
rect: albumImageView.frame,
options: [.mouseEnteredAndExited, .activeAlways],
owner: self,
userInfo: nil
)
self.trackingArea = trackingArea
addTrackingArea(trackingArea)
}
required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
NotificationCenter.default.addObserver(
self,
selector: #selector(viewWillScroll(_:)),
name: NSScrollView.willStartLiveScrollNotification,
object: nil
)
}
@objc func viewWillScroll(_ notification: Notification) {
hidePlayButton()
}
override func resize(withOldSuperviewSize oldSize: NSSize) {
hidePlayButton()
}
override func mouseEntered(with event: NSEvent) {
showPlayButton()
}
override func mouseExited(with event: NSEvent) {
hidePlayButton()
}
func showPlayButton() {
playButton.isHidden = false
}
func hidePlayButton() {
playButton.isHidden = true
}
@IBOutlet var imageView: NSImageView!
@IBOutlet var playButton: NSButton!
}