KMBotaLeftView.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // KMBotaLeftView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/11/22.
  6. //
  7. import Cocoa
  8. class KMBotaLeftView: NSView {
  9. var segmentedControl: KMSegmentedControl = {
  10. let view = KMSegmentedControl()
  11. return view
  12. }()
  13. var helpButton: KMCoverButton = {
  14. let view = KMCoverButton()
  15. view.title = ""
  16. view.image = NSImage(named: "KMImgNameUserFbHelpIcon")
  17. view.isBordered = false
  18. return view
  19. }()
  20. var ttsButton: NSButton = {
  21. let view = NSButton()
  22. view.title = ""
  23. view.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTTS)
  24. view.isBordered = false
  25. view.imageScaling = NSImageScaling.scaleAxesIndependently
  26. return view
  27. }()
  28. var itemClick: KMItemClickBlock<KMBotaLeftView>?
  29. override init(frame frameRect: NSRect) {
  30. super.init(frame: frameRect)
  31. self.initSubview()
  32. self.initDefaultValue()
  33. }
  34. required init?(coder: NSCoder) {
  35. super.init(coder: coder)
  36. self.initSubview()
  37. self.initDefaultValue()
  38. }
  39. func initSubview() {
  40. self.addSubview(self.segmentedControl)
  41. self.addSubview(self.helpButton)
  42. self.addSubview(self.ttsButton)
  43. self.ttsButton.target = self
  44. self.ttsButton.action = #selector(ttsAction)
  45. }
  46. func initDefaultValue() {
  47. self.segmentedControl.direction = .vertical
  48. // self.segmentedControl.setSegmentCount(5, with: 44)
  49. // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 0)
  50. // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 1)
  51. // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 2)
  52. // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 3)
  53. // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 4)
  54. // self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails"), for: 0)
  55. // self.segmentedControl.setToolTip(KMLocalizedString("View Outline"), for: 1)
  56. // self.segmentedControl.setToolTip(KMLocalizedString("View Notes"), for: 2)
  57. // self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots"), for: 3)
  58. // self.segmentedControl.setToolTip(KMLocalizedString("Search"), for: 4)
  59. self.segmentedControl.setSegmentCount(6, with: 44)
  60. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 0)
  61. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 1)
  62. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 2)
  63. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 3)
  64. self.segmentedControl.setImage(NSImage(named: "KMImageNameSidebarBookMarkNor")!, for: 4)
  65. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 5)
  66. self.segmentedControl.setToolTip(NSLocalizedString("Search", comment: ""), for: 0)
  67. self.segmentedControl.setToolTip(NSLocalizedString("View Thumbnails", comment: ""), for: 1)
  68. self.segmentedControl.setToolTip(NSLocalizedString("View Outline", comment: ""), for: 2)
  69. self.segmentedControl.setToolTip(NSLocalizedString("View Notes", comment: ""), for: 3)
  70. self.segmentedControl.setToolTip(NSLocalizedString("View Bookmarks", comment: ""), for: 4)
  71. self.segmentedControl.setToolTip(NSLocalizedString("View Snapshots", comment: ""), for: 5)
  72. self.segmentedControl.selectedSegment = UInt8.max
  73. self.segmentedControl.wantsLayer = true
  74. self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  75. }
  76. override func layout() {
  77. super.layout()
  78. self.segmentedControl.frame = self.bounds
  79. self.helpButton.frame = NSMakeRect(4, 0, 36, 36)
  80. self.ttsButton.frame = NSMakeRect(14, NSMaxY(self.helpButton.frame)+6, 16, 16)
  81. }
  82. override func draw(_ dirtyRect: NSRect) {
  83. super.draw(dirtyRect)
  84. }
  85. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  86. super.interfaceThemeDidChanged(appearance)
  87. self.segmentedControl.appearance = .init(named: appearance)
  88. self.segmentedControl.wantsLayer = true
  89. // self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  90. if KMAppearance.isDarkMode() {
  91. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
  92. } else {
  93. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#EBECF0", alpha: 1).cgColor
  94. }
  95. }
  96. @objc func ttsAction() {
  97. self.itemClick?(self, 1)
  98. }
  99. }