KMBotaLeftView.swift 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. override init(frame frameRect: NSRect) {
  21. super.init(frame: frameRect)
  22. self.initSubview()
  23. self.initDefaultValue()
  24. }
  25. required init?(coder: NSCoder) {
  26. super.init(coder: coder)
  27. self.initSubview()
  28. self.initDefaultValue()
  29. }
  30. func initSubview() {
  31. self.addSubview(self.segmentedControl)
  32. self.addSubview(self.helpButton)
  33. }
  34. func initDefaultValue() {
  35. self.segmentedControl.direction = .vertical
  36. self.segmentedControl.setSegmentCount(6, with: 44)
  37. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 0)
  38. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 1)
  39. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 2)
  40. self.segmentedControl.setImage(NSImage(named: "KMImageNameSidebarBookMarkNor")!, for: 3)
  41. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 4)
  42. self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 5)
  43. self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails", nil), for: 0)
  44. self.segmentedControl.setToolTip(KMLocalizedString("View Outline", nil), for: 1)
  45. self.segmentedControl.setToolTip(KMLocalizedString("View Notes", nil), for: 2)
  46. self.segmentedControl.setToolTip(KMLocalizedString("View Bookmark", nil), for: 3)
  47. self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots", nil), for: 4)
  48. self.segmentedControl.setToolTip(KMLocalizedString("Search", nil), for: 5)
  49. self.segmentedControl.selectedSegment = UInt8.max
  50. self.segmentedControl.wantsLayer = true
  51. self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  52. }
  53. override func layout() {
  54. super.layout()
  55. self.segmentedControl.frame = self.bounds
  56. self.helpButton.frame = NSMakeRect(0, 0, 36, 36)
  57. }
  58. override func draw(_ dirtyRect: NSRect) {
  59. super.draw(dirtyRect)
  60. }
  61. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  62. super.interfaceThemeDidChanged(appearance)
  63. self.segmentedControl.appearance = .init(named: appearance)
  64. self.segmentedControl.wantsLayer = true
  65. // self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  66. if KMAppearance.isDarkMode() {
  67. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
  68. } else {
  69. self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#EBECF0", alpha: 1).cgColor
  70. }
  71. }
  72. }