KMTextAlignmentController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // KMTextAlignmentController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/6/26.
  6. //
  7. import Cocoa
  8. class KMTextAlignmentController: NSViewController {
  9. @IBOutlet weak var leftBox: NSBox!
  10. @IBOutlet weak var centerBox: NSBox!
  11. @IBOutlet weak var rightBox: NSBox!
  12. private var leftVc_: KMDesignButton?
  13. private var centerVc_: KMDesignButton?
  14. private var rightVc_: KMDesignButton?
  15. var itemAction: KMCommonClickBlock?
  16. var align: NSTextAlignment = .center {
  17. didSet {
  18. let data = self.align
  19. if data == .left {
  20. self.leftVc_?.state = .Act
  21. self.centerVc_?.state = .Norm
  22. self.rightVc_?.state = .Norm
  23. } else if data == .center {
  24. self.leftVc_?.state = .Norm
  25. self.centerVc_?.state = .Act
  26. self.rightVc_?.state = .Norm
  27. } else if data == .right {
  28. self.leftVc_?.state = .Norm
  29. self.centerVc_?.state = .Norm
  30. self.rightVc_?.state = .Act
  31. }
  32. }
  33. }
  34. override func viewWillAppear() {
  35. super.viewWillAppear()
  36. self.reloadData()
  37. }
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. self.view.wantsLayer = true
  41. self.leftVc_ = KMDesignButton(withType: .Image)
  42. self.leftBox.contentView = self.leftVc_!.view
  43. self.leftBox.borderWidth = 0
  44. self.leftVc_?.pagination()
  45. self.leftVc_?.target = self
  46. self.leftVc_?.action = #selector(_itemClick)
  47. self.leftVc_?.image = NSImage(named: "KMImageNameEditPDFAlignLeftSelect")!
  48. self.leftVc_?.tag = 0
  49. self.leftVc_?.initDefaultValue()
  50. self.leftVc_?.borderWidth = 0
  51. self.leftVc_?.borderWidth_hov = 0
  52. self.leftVc_?.borderWidth_act = 0
  53. self.centerVc_ = KMDesignButton(withType: .Image)
  54. self.centerBox.contentView = self.centerVc_!.view
  55. self.centerBox.borderWidth = 0
  56. self.centerVc_?.pagination()
  57. self.centerVc_?.target = self
  58. self.centerVc_?.action = #selector(_itemClick)
  59. self.centerVc_?.image = NSImage(named: "KMImageNameEditPDFAlignCenterSelect")!
  60. self.centerVc_?.tag = 1
  61. self.centerVc_?.initDefaultValue()
  62. self.centerVc_?.borderWidth = 0
  63. self.centerVc_?.borderWidth_hov = 0
  64. self.centerVc_?.borderWidth_act = 0
  65. self.rightVc_ = KMDesignButton(withType: .Image)
  66. self.rightBox.contentView = self.rightVc_!.view
  67. self.rightBox.borderWidth = 0
  68. self.rightVc_?.pagination()
  69. self.rightVc_?.target = self
  70. self.rightVc_?.action = #selector(_itemClick)
  71. self.rightVc_?.image = NSImage(named: "KMImageNameEditPDFAlignRightSelect")!
  72. self.rightVc_?.tag = 2
  73. self.rightVc_?.initDefaultValue()
  74. self.rightVc_?.borderWidth = 0
  75. self.rightVc_?.borderWidth_hov = 0
  76. self.rightVc_?.borderWidth_act = 0
  77. self.reloadData()
  78. }
  79. @objc private func _itemClick(_ sender: NSButton) {
  80. self.itemAction?(sender.tag)
  81. }
  82. func reloadData() {
  83. self.view.wantsLayer = true
  84. self.leftBox.fillColor = .clear
  85. self.centerBox.fillColor = .clear
  86. self.rightBox.fillColor = .clear
  87. if KMAppearance.isDarkMode() {
  88. // self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  89. self.view.layer?.backgroundColor = NSColor.km_init(hex: "#26282B").cgColor
  90. self.leftVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  91. self.centerVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  92. self.rightVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  93. leftVc_?.background = NSColor.clear
  94. leftVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  95. leftVc_?.background_act = KMAppearance.Interactive.m1Color()
  96. centerVc_?.background = NSColor.clear
  97. centerVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  98. centerVc_?.background_act = KMAppearance.Interactive.m1Color()
  99. rightVc_?.background = NSColor.clear
  100. rightVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  101. rightVc_?.background_act = KMAppearance.Interactive.m1Color()
  102. } else {
  103. self.view.layer?.backgroundColor = .white
  104. self.leftVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  105. self.centerVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  106. self.rightVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  107. }
  108. }
  109. }