KMAnnotationSectionCellView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. @IBOutlet weak var titleLeftConst: NSLayoutConstraint!
  14. var contentInset: NSEdgeInsets = .init()
  15. var itemClick: KMCommonClickBlock?
  16. var isExpand = false {
  17. didSet {
  18. if self.isExpand {
  19. self.expandButton.image = NSImage(named: "KMImageNameBotaNoteExpand")
  20. } else {
  21. self.expandButton.image = NSImage(named: "KMImageNameBotaNoteNoExpand")
  22. }
  23. }
  24. }
  25. override func draw(_ dirtyRect: NSRect) {
  26. super.draw(dirtyRect)
  27. // Drawing code here.
  28. }
  29. override func awakeFromNib() {
  30. super.awakeFromNib()
  31. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  32. countLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  33. NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: APPAppearanceChangedNotificationName, object: nil)
  34. self.updateUI()
  35. self.expandButton.target = self
  36. self.expandButton.action = #selector(expandAction)
  37. }
  38. @objc func expandAction() {
  39. self.itemClick?(1)
  40. }
  41. @objc func updateUI() {
  42. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  43. countLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/3")
  44. }
  45. override func updateLayer() {
  46. super.updateLayer()
  47. self.updateUI()
  48. }
  49. }