// // KMHomeQuickToolsWindowCollectionViewItem.swift // PDF Reader Pro // // Created by lizhe on 2023/10/31. // import Cocoa class KMHomeQuickToolsWindowCollectionViewItem: NSCollectionViewItem { @IBOutlet weak var iconImageView: NSImageView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var box: KMBox! override var highlightState: NSCollectionViewItem.HighlightState { didSet { if highlightState == .forSelection { self.updateState(isHight: true) } else if highlightState == .forDeselection { self.updateState(isHight: false) } } } override var isSelected: Bool { didSet { self.updateState(isHight: false) } } var model: KMQucikToolsModel? { didSet { self.reloadData() } } override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.setup() } func setup() { self.box.fillColor = NSColor.clear self.titleLabel.textColor = KMAppearance.Layout.h2Color() self.box.moveCallback = { [weak self] mouseEntered, mouseBox in self?.updateState(isHight: mouseEntered) } } func reloadData() { guard let model = model else { return } titleLabel.stringValue = model.titleString() iconImageView.image = model.iconImage() } func updateState(isHight: Bool) { if isHight || self.isSelected { box.fillColor = KMAppearance.Interactive.a0Color() titleLabel.textColor = KMAppearance.Layout.w0Color() iconImageView.image = model?.iconImage(true) } else { box.fillColor = NSColor.clear titleLabel.textColor = KMAppearance.Layout.h2Color() iconImageView.image = model?.iconImage(false) } } }