123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // 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)
- }
- }
- }
|