KMHomeQuickToolsWindowCollectionViewItem.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // KMHomeQuickToolsWindowCollectionViewItem.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/10/31.
  6. //
  7. import Cocoa
  8. class KMHomeQuickToolsWindowCollectionViewItem: NSCollectionViewItem {
  9. @IBOutlet weak var iconImageView: NSImageView!
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var box: KMBox!
  12. override var highlightState: NSCollectionViewItem.HighlightState {
  13. didSet {
  14. if highlightState == .forSelection {
  15. self.updateState(isHight: true)
  16. } else if highlightState == .forDeselection {
  17. self.updateState(isHight: false)
  18. }
  19. }
  20. }
  21. override var isSelected: Bool {
  22. didSet {
  23. self.updateState(isHight: false)
  24. }
  25. }
  26. var model: KMQucikToolsModel? {
  27. didSet {
  28. self.reloadData()
  29. }
  30. }
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33. // Do view setup here.
  34. self.setup()
  35. }
  36. func setup() {
  37. self.box.fillColor = NSColor.clear
  38. self.titleLabel.textColor = KMAppearance.Layout.h2Color()
  39. self.box.moveCallback = { [weak self] mouseEntered, mouseBox in
  40. self?.updateState(isHight: mouseEntered)
  41. }
  42. }
  43. func reloadData() {
  44. guard let model = model else { return }
  45. titleLabel.stringValue = model.titleString()
  46. iconImageView.image = model.iconImage()
  47. }
  48. func updateState(isHight: Bool) {
  49. if isHight || self.isSelected {
  50. box.fillColor = KMAppearance.Interactive.a0Color()
  51. titleLabel.textColor = KMAppearance.Layout.w0Color()
  52. iconImageView.image = model?.iconImage(true)
  53. } else {
  54. box.fillColor = NSColor.clear
  55. titleLabel.textColor = KMAppearance.Layout.h2Color()
  56. iconImageView.image = model?.iconImage(false)
  57. }
  58. }
  59. }