KMBotaLeftView.swift 2.7 KB

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