KMAnnotationSectionCellView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // KMSectionCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/9/18.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMAnnotationSectionCellView: NSTableCellView, NibLoadable {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var countLabel: NSTextField!
  12. @IBOutlet weak var expandButton: NSButton!
  13. var contentInset: NSEdgeInsets = .init()
  14. var itemClick: KMCommonClickBlock?
  15. var isExpand = false {
  16. didSet {
  17. if self.isExpand {
  18. self.expandButton.image = NSImage(named: "KMImageNameBotaNoteExpand")
  19. } else {
  20. self.expandButton.image = NSImage(named: "KMImageNameBotaNoteNoExpand")
  21. }
  22. }
  23. }
  24. override func draw(_ dirtyRect: NSRect) {
  25. super.draw(dirtyRect)
  26. // Drawing code here.
  27. }
  28. override func awakeFromNib() {
  29. super.awakeFromNib()
  30. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  31. countLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  32. NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: APPAppearanceChangedNotificationName, object: nil)
  33. self.updateUI()
  34. self.expandButton.target = self
  35. self.expandButton.action = #selector(expandAction)
  36. }
  37. @objc func expandAction() {
  38. self.itemClick?(1)
  39. }
  40. @objc func updateUI() {
  41. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  42. countLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/3")
  43. }
  44. override func updateLayer() {
  45. super.updateLayer()
  46. self.updateUI()
  47. }
  48. }