KMBotaLeftView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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(6, with: 44)
  49. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 0)
  50. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 1)
  51. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 2)
  52. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 3)
  53. self.segmentedControl.setImage(NSImage(named: "KMImageNameSidebarBookMarkNor")!, for: 4)
  54. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 5)
  55. self.segmentedControl.setToolTip(KMLocalizedString("Search", nil), for: 0)
  56. self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails", nil), for: 1)
  57. self.segmentedControl.setToolTip(KMLocalizedString("View Outline", nil), for: 2)
  58. self.segmentedControl.setToolTip(KMLocalizedString("View Notes", nil), for: 3)
  59. self.segmentedControl.setToolTip(KMLocalizedString("View Bookmarks", nil), for: 4)
  60. self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots", nil), for: 5)
  61. self.segmentedControl.selectedSegment = UInt8.max
  62. self.segmentedControl.wantsLayer = true
  63. self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  64. }
  65. override func layout() {
  66. super.layout()
  67. self.segmentedControl.frame = self.bounds
  68. self.helpButton.frame = NSMakeRect(4, 0, 36, 36)
  69. self.ttsButton.frame = NSMakeRect(14, NSMaxY(self.helpButton.frame)+6, 16, 16)
  70. }
  71. override func draw(_ dirtyRect: NSRect) {
  72. super.draw(dirtyRect)
  73. }
  74. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  75. super.interfaceThemeDidChanged(appearance)
  76. self.segmentedControl.appearance = .init(named: appearance)
  77. self.segmentedControl.wantsLayer = true
  78. // self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  79. if KMAppearance.isDarkMode() {
  80. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
  81. } else {
  82. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#EBECF0", alpha: 1).cgColor
  83. }
  84. }
  85. @objc func ttsAction() {
  86. self.itemClick?(self, 1)
  87. }
  88. }