KMBatesPageInfoView.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // KMBatesPageInfoView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/28.
  6. //
  7. import Cocoa
  8. class KMBatesPageInfoView: KMHeaderFooterAdjectiveInfoBaseView {
  9. var leftLabel = NSTextField(labelWithString: "")
  10. var leftStepper = KMWatermarkAdjectiveStepper()
  11. private var rigthLabel = NSTextField(labelWithString: "")
  12. var rightComboBox = NSComboBox()
  13. override func initSubviews() {
  14. super.initSubviews()
  15. self.addSubview(self.leftLabel)
  16. self.addSubview(self.leftStepper)
  17. self.addSubview(self.rigthLabel)
  18. self.addSubview(self.rightComboBox)
  19. self.titleLabel.isHidden = true
  20. self.leftLabel.stringValue = NSLocalizedString("Numbers of Digits:", comment: "")
  21. self.rigthLabel.stringValue = NSLocalizedString("Start Page:", comment: "")
  22. self.leftStepper.wantsLayer = true
  23. self.leftStepper.layer?.borderWidth = 1
  24. self.leftStepper.layer?.borderColor = NSColor.black.cgColor
  25. self.leftStepper.stepper.minValue = 1
  26. self.leftStepper.stepper.maxValue = 99
  27. self.leftStepper.valueDidChange = {
  28. (value: Double) in
  29. guard let callback = self.itemClick else {
  30. return
  31. }
  32. callback(1, value)
  33. }
  34. self.rightComboBox.isEditable = false
  35. self.rightComboBox.delegate = self
  36. }
  37. override func layout() {
  38. super.layout()
  39. let width: CGFloat = NSWidth(self.bounds)
  40. let hSpace: CGFloat = 10
  41. let leftMargin = self.contentInset.left
  42. let labelWidth: CGFloat = (width-leftMargin*2-hSpace)*0.5
  43. let labelHeight: CGFloat = 16
  44. self.leftLabel.frame = NSMakeRect(leftMargin, 0, labelWidth, labelHeight)
  45. self.rigthLabel.frame = NSMakeRect(self.rigthLabel.frame.maxX+hSpace, 0, labelWidth, labelHeight)
  46. let comboBoxY: CGFloat = self.leftLabel.frame.maxY+6
  47. let comboBoxSize: NSSize = NSMakeSize(labelWidth, 22)
  48. self.leftStepper.frame = NSMakeRect(leftMargin, comboBoxY, comboBoxSize.width, 30)
  49. self.rightComboBox.frame = NSMakeRect(self.leftStepper.frame.maxX+hSpace, comboBoxY, comboBoxSize.width, comboBoxSize.height)
  50. }
  51. override var model: KMHeaderFooterAdjectiveModel {
  52. get {
  53. super.model
  54. }
  55. set {
  56. super.model = newValue
  57. }
  58. }
  59. }
  60. extension KMBatesPageInfoView: NSComboBoxDelegate {
  61. func comboBoxSelectionDidChange(_ notification: Notification) {
  62. if (self.rightComboBox.isEqual(to: notification.object)) {
  63. guard let callback = self.itemClick else {
  64. return
  65. }
  66. var index: Int = self.rightComboBox.indexOfSelectedItem
  67. if (index < 0) {
  68. index = 0
  69. }
  70. callback(2, index)
  71. }
  72. }
  73. }