KMHeaderFooterMarginInfoView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // KMHeaderFooterMarginInfoView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/27.
  6. //
  7. import Cocoa
  8. class KMHeaderFooterMarginInfoView: KMHeaderFooterAdjectiveInfoBaseView {
  9. var topLabel = NSTextField(labelWithString: "")
  10. var topStepper = KMWatermarkAdjectiveStepper()
  11. var bottomLabel = NSTextField(labelWithString: "")
  12. var bottomStepper = KMWatermarkAdjectiveStepper()
  13. var leftLabel = NSTextField(labelWithString: "")
  14. var leftStepper = KMWatermarkAdjectiveStepper()
  15. var rightLabel = NSTextField(labelWithString: "")
  16. var rightStepper = KMWatermarkAdjectiveStepper()
  17. override func initSubviews() {
  18. super.initSubviews()
  19. self.addSubview(self.topLabel)
  20. self.addSubview(self.topStepper)
  21. self.addSubview(self.bottomLabel)
  22. self.addSubview(self.bottomStepper)
  23. self.addSubview(self.leftLabel)
  24. self.addSubview(self.leftStepper)
  25. self.addSubview(self.rightLabel)
  26. self.addSubview(self.rightStepper)
  27. self.titleLabel.stringValue = NSLocalizedString("Margin(mm)", comment: "")
  28. self.topLabel.stringValue = NSLocalizedString("", comment: "")
  29. self.bottomLabel.stringValue = NSLocalizedString("", comment: "")
  30. self.leftLabel.stringValue = NSLocalizedString("", comment: "")
  31. self.rightLabel.stringValue = NSLocalizedString("", comment: "")
  32. for label in [self.topLabel, self.bottomLabel, self.leftLabel, self.rightLabel] {
  33. label.alignment = .center
  34. }
  35. for stepper in [self.topStepper, self.bottomStepper, self.leftStepper, self.rightStepper] {
  36. stepper.wantsLayer = true
  37. stepper.layer?.borderWidth = 1
  38. stepper.layer?.borderColor = NSColor.black.cgColor
  39. }
  40. self.topStepper.valueDidChange = {
  41. (value: Double) in
  42. guard let callback = self.itemClick else {
  43. return
  44. }
  45. callback(1, value)
  46. }
  47. self.bottomStepper.valueDidChange = {
  48. (value: Double) in
  49. guard let callback = self.itemClick else {
  50. return
  51. }
  52. callback(2, value)
  53. }
  54. self.leftStepper.valueDidChange = {
  55. (value: Double) in
  56. guard let callback = self.itemClick else {
  57. return
  58. }
  59. callback(3, value)
  60. }
  61. self.rightStepper.valueDidChange = {
  62. (value: Double) in
  63. guard let callback = self.itemClick else {
  64. return
  65. }
  66. callback(4, value)
  67. }
  68. }
  69. override func layout() {
  70. super.layout()
  71. let width: CGFloat = NSWidth(self.bounds)
  72. let leftMargin = self.contentInset.left
  73. let topY = self.titleLabel.frame.maxY + 10
  74. let stepperSize: NSSize = NSMakeSize(60, 32)
  75. let labelSize: NSSize = NSMakeSize(32, 20)
  76. self.topLabel.frame = NSMakeRect(leftMargin-8, topY+8, labelSize.width, labelSize.height)
  77. self.topStepper.frame = NSMakeRect(self.topLabel.frame.maxX, topY, stepperSize.width, stepperSize.height)
  78. let rightLabelX: CGFloat = width-self.contentInset.right-stepperSize.width-10-labelSize.width
  79. self.bottomLabel.frame = NSMakeRect(rightLabelX, topY+8, labelSize.width, labelSize.height)
  80. self.bottomStepper.frame = NSMakeRect(self.bottomLabel.frame.maxX, topY, stepperSize.width, stepperSize.height)
  81. self.leftLabel.frame = NSMakeRect(leftMargin-8, self.topStepper.frame.maxY+18, labelSize.width, labelSize.height)
  82. self.leftStepper.frame = NSMakeRect(self.topLabel.frame.maxX, self.topStepper.frame.maxY+18, stepperSize.width, stepperSize.height)
  83. self.rightLabel.frame = NSMakeRect(rightLabelX, self.topStepper.frame.maxY+18, labelSize.width, labelSize.height)
  84. self.rightStepper.frame = NSMakeRect(self.rightLabel.frame.maxX, self.topStepper.frame.maxY+18, stepperSize.width, stepperSize.height)
  85. }
  86. override var model: KMHeaderFooterAdjectiveModel {
  87. get {
  88. return super.model
  89. }
  90. set {
  91. super.model = newValue
  92. self.topStepper.value = Double(newValue.topMargin)
  93. self.bottomStepper.value = Double(newValue.bottomMargin)
  94. self.leftStepper.value = Double(newValue.leftMargin)
  95. self.rightStepper.value = Double(newValue.rightMargin)
  96. }
  97. }
  98. }