KMTextAlignmentController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 viewDidLoad() {
  35. super.viewDidLoad()
  36. self.view.wantsLayer = true
  37. self.leftVc_ = KMDesignButton(withType: .Image)
  38. self.leftBox.contentView = self.leftVc_!.view
  39. self.leftBox.borderWidth = 0
  40. self.leftVc_?.pagination()
  41. self.leftVc_?.target = self
  42. self.leftVc_?.action = #selector(_itemClick)
  43. self.leftVc_?.image = NSImage(named: "KMImageNameEditPDFAlignLeftSelect")!
  44. self.leftVc_?.tag = 0
  45. self.leftVc_?.initDefaultValue()
  46. self.leftVc_?.borderWidth = 0
  47. self.leftVc_?.borderWidth_hov = 0
  48. self.leftVc_?.borderWidth_act = 0
  49. self.centerVc_ = KMDesignButton(withType: .Image)
  50. self.centerBox.contentView = self.centerVc_!.view
  51. self.centerBox.borderWidth = 0
  52. self.centerVc_?.pagination()
  53. self.centerVc_?.target = self
  54. self.centerVc_?.action = #selector(_itemClick)
  55. self.centerVc_?.image = NSImage(named: "KMImageNameEditPDFAlignCenterSelect")!
  56. self.centerVc_?.tag = 1
  57. self.centerVc_?.initDefaultValue()
  58. self.centerVc_?.borderWidth = 0
  59. self.centerVc_?.borderWidth_hov = 0
  60. self.centerVc_?.borderWidth_act = 0
  61. self.rightVc_ = KMDesignButton(withType: .Image)
  62. self.rightBox.contentView = self.rightVc_!.view
  63. self.rightBox.borderWidth = 0
  64. self.rightVc_?.pagination()
  65. self.rightVc_?.target = self
  66. self.rightVc_?.action = #selector(_itemClick)
  67. self.rightVc_?.image = NSImage(named: "KMImageNameEditPDFAlignRightSelect")!
  68. self.rightVc_?.tag = 2
  69. self.rightVc_?.initDefaultValue()
  70. self.rightVc_?.borderWidth = 0
  71. self.rightVc_?.borderWidth_hov = 0
  72. self.rightVc_?.borderWidth_act = 0
  73. self.reloadData()
  74. }
  75. @objc private func _itemClick(_ sender: NSButton) {
  76. self.itemAction?(sender.tag)
  77. }
  78. func reloadData() {
  79. if KMAppearance.isDarkMode() {
  80. self.view.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  81. self.leftVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  82. self.centerVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  83. self.rightVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  84. leftVc_?.background = NSColor.clear
  85. leftVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  86. leftVc_?.background_act = KMAppearance.Interactive.m1Color()
  87. centerVc_?.background = NSColor.clear
  88. centerVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  89. centerVc_?.background_act = KMAppearance.Interactive.m1Color()
  90. rightVc_?.background = NSColor.clear
  91. rightVc_?.background_hov = NSColor(red: 71/255, green: 72/255, blue: 75/255, alpha: 1)
  92. rightVc_?.background_act = KMAppearance.Interactive.m1Color()
  93. } else {
  94. self.view.layer?.backgroundColor = .white
  95. self.leftVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  96. self.centerVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  97. self.rightVc_?.background_hov = NSColor(red: 237/255, green: 238/255, blue: 240/255, alpha: 1)
  98. }
  99. }
  100. }