KMPageEditInsertDirectionItemView.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // KMPageEditInsertDirectionItemView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/1/11.
  6. //
  7. import Cocoa
  8. class KMPageEditInsertDirectionItemView: KMPageEditBaseItemView {
  9. private var horVC: KMDesignButton?
  10. private var verVC: KMDesignButton?
  11. override func initSubviews() {
  12. super.initSubviews()
  13. self.horVC = KMDesignButton(withType: .RadioButton)
  14. self.addSubview(self.horVC!.view)
  15. self.horVC?.target = self
  16. self.horVC?.action = #selector(horAction)
  17. self.horVC?.stringValue = NSLocalizedString("Horizontal page", comment: "")
  18. self.verVC = KMDesignButton(withType: .RadioButton)
  19. self.addSubview(self.verVC!.view)
  20. self.verVC?.target = self
  21. self.verVC?.action = #selector(verAction)
  22. self.verVC?.stringValue = NSLocalizedString("Vertical pages", comment: "")
  23. self.titleLabel.stringValue = NSLocalizedString("Direction", comment: "")
  24. self.titleLabel.font = .SFProTextSemiboldFont(12)
  25. self.titleLabel.textColor = NSColor.km_init(hex: "#616469")
  26. self.horVC?.state = .Norm
  27. self.verVC?.state = .Checked
  28. }
  29. override func layout() {
  30. super.layout()
  31. let raidoY: CGFloat = self.titleLabel.frame.maxY
  32. let radioSize = NSSize(width: 150, height: 22)
  33. self.verVC?.view.frame = NSMakeRect(self.contentInset.left, raidoY, radioSize.width, radioSize.height)
  34. self.horVC?.view.frame = NSMakeRect(self.contentInset.left + radioSize.width, raidoY , radioSize.width, radioSize.height)
  35. }
  36. @objc private func horAction() {
  37. self.verVC?.state = .Norm
  38. self.horVC?.state = .Checked
  39. guard let callback = self.itemClick else {
  40. return
  41. }
  42. callback(1, "")
  43. }
  44. @objc private func verAction() {
  45. self.horVC?.state = .Norm
  46. self.verVC?.state = .Checked
  47. guard let callback = self.itemClick else {
  48. return
  49. }
  50. callback(2, "")
  51. }
  52. public func switchDirection(isHor: Bool) {
  53. self.horVC?.state = .Norm
  54. self.verVC?.state = .Norm
  55. if (isHor) {
  56. self.horVC?.state = .Checked
  57. } else {
  58. self.verVC?.state = .Checked
  59. }
  60. }
  61. public func getDirection() -> Int {
  62. if let state = self.horVC?.state {
  63. return state == .Checked ? 1 : 0
  64. }
  65. return 0
  66. }
  67. }