InputDemoVC.swift 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // InputDemoVC.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/8/26.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class InputDemoVC: NSViewController {
  10. //Input
  11. @IBOutlet weak var componentInput: ComponentInput!
  12. @IBOutlet weak var inputHeightConst: NSLayoutConstraint!
  13. @IBOutlet weak var inputSizeBox: NSComboBox!
  14. @IBOutlet weak var inputErrorBtn: NSButton!
  15. @IBOutlet weak var inputDisableBtn: NSButton!
  16. @IBOutlet weak var inputShowClearBtn: NSButton!
  17. @IBOutlet weak var inputShowPrefixBtn: NSButton!
  18. @IBOutlet weak var inputShowSuffixBtn: NSButton!
  19. //Textare
  20. @IBOutlet weak var componentTextarea: ComponentTextarea!
  21. @IBOutlet weak var textareaDisableBtn: NSButton!
  22. //Password
  23. @IBOutlet weak var passwordView: ComponentPasswordView!
  24. @IBOutlet weak var passwordErrorBtn: NSButton!
  25. @IBOutlet weak var passwordDisableBtn: NSButton!
  26. @IBOutlet weak var passwordHeightConst: NSLayoutConstraint!
  27. //Addon
  28. @IBOutlet weak var addOnItem: ComponentInputAddon!
  29. @IBOutlet weak var addOnHeightConst: NSLayoutConstraint!
  30. @IBOutlet weak var addOnWidthConst: NSLayoutConstraint!
  31. @IBOutlet weak var addonBeforeBtn: NSButton!
  32. @IBOutlet weak var addonDisableBtn: NSButton!
  33. @IBOutlet weak var addonsizeBox: NSComboBox!
  34. @IBOutlet weak var addonTypeBox: NSComboBox!
  35. @IBOutlet weak var addonOnlyReadBtn: NSButton!
  36. //InputWithAddon
  37. @IBOutlet weak var inputWithAddon: ComponentInputWithAddon!
  38. @IBOutlet weak var inputWithAddonType: NSComboBox!
  39. @IBOutlet weak var inputWithAddonSize: NSComboBox!
  40. @IBOutlet weak var inputWithAddonDisableBtn: NSButton!
  41. @IBOutlet weak var inputWithAddonHeightConst: NSLayoutConstraint!
  42. override func viewDidLoad() {
  43. super.viewDidLoad(
  44. )
  45. // Do view setup here.
  46. self.addonTypeBox.selectItem(at: 0)
  47. self.inputWithAddonType.selectItem(at: 0)
  48. self.reloadData()
  49. self.addOnItem.setTarget(self, action: #selector(addOnItemClick(_:)))
  50. }
  51. func reloadData() {
  52. //Input
  53. var inputSize: ComponentSize = .m
  54. if self.inputSizeBox.indexOfSelectedItem == 1 {
  55. inputSize = .s
  56. } else if self.inputSizeBox.indexOfSelectedItem == 2 {
  57. inputSize = .xs
  58. } else if self.inputSizeBox.indexOfSelectedItem == 3 {
  59. inputSize = .xxs
  60. }
  61. let inputProperty: ComponentInputProperty = ComponentInputProperty(size: inputSize,
  62. state: .normal,
  63. isError: self.inputErrorBtn.state == .on,
  64. showPrefix: self.inputShowPrefixBtn.state == .on,
  65. showSuffix: self.inputShowSuffixBtn.state == .on,
  66. showClear: self.inputShowClearBtn.state == .on,
  67. isDisabled: self.inputDisableBtn.state == .on,
  68. placeholder: "Please enter...",
  69. text: componentInput.properties.text)
  70. self.componentInput.properties = inputProperty
  71. self.inputHeightConst.constant = self.componentInput.properties.propertyInfo.viewHeight
  72. //Textarea
  73. let textareaProperty: ComponentTextareaProperty = ComponentTextareaProperty(size: .m,
  74. state: .normal,
  75. isError: false,
  76. placeholderString: "Please enter...",
  77. totalCount: 100,
  78. text: self.componentTextarea.properties.text,
  79. isDisabled:self.textareaDisableBtn.state == .on)
  80. self.componentTextarea.properties = textareaProperty
  81. //Password
  82. let passwordProperty: ComponentPasswordProperty = ComponentPasswordProperty(size: .m,
  83. state: .normal,
  84. isError: self.passwordErrorBtn.state == .on,
  85. placeholderString: "Please enter password",
  86. text: "",
  87. isDisabled: self.passwordDisableBtn.state == .on,
  88. errorText: "Here is the error message description.")
  89. self.passwordView.properties = passwordProperty
  90. self.passwordHeightConst.constant = passwordProperty.propertyInfo.viewHeight
  91. //Addon
  92. var addonSize: ComponentSize = .m
  93. if self.addonsizeBox.indexOfSelectedItem == 1 {
  94. addonSize = .s
  95. }
  96. self.addonOnlyReadBtn.isEnabled = true
  97. var addonType: InputAddonType = .text
  98. if self.addonTypeBox.indexOfSelectedItem == 0 {
  99. self.addonOnlyReadBtn.isEnabled = false
  100. self.addonOnlyReadBtn.state = .on
  101. } else if self.addonTypeBox.indexOfSelectedItem == 1 {
  102. addonType = .textWithColor
  103. } else if self.addonTypeBox.indexOfSelectedItem == 2 {
  104. addonType = .imageWithColor
  105. } else if self.addonTypeBox.indexOfSelectedItem == 3 {
  106. addonType = .dropDown
  107. }
  108. let addonProperty: ComponentInputAddonProperty = ComponentInputAddonProperty(size: addonSize,
  109. state: .normal,
  110. isDisabled: self.addonDisableBtn.state == .on,
  111. addOnBefore: self.addonBeforeBtn.state == .on,
  112. onlyRead: self.addonOnlyReadBtn.state == .on,
  113. addonType: addonType,
  114. iconImage: ComponentLibrary.shared.image(forResource: "test"),
  115. text: "add-on")
  116. self.addOnItem.properties = addonProperty
  117. self.addOnWidthConst.constant = self.addOnItem.properties.propertyInfo.viewWidth
  118. self.addOnHeightConst.constant = self.addOnItem.properties.propertyInfo.viewHeight
  119. //Input With Addon
  120. var inputWithSize: ComponentSize = .m
  121. if self.inputWithAddonSize.indexOfSelectedItem == 1 {
  122. inputWithSize = .s
  123. }
  124. var inputWithType: InputWithAddonType = .text
  125. if self.inputWithAddonType.indexOfSelectedItem == 1 {
  126. inputWithType = .button
  127. } else if self.inputWithAddonType.indexOfSelectedItem == 2 {
  128. inputWithType = .dropdown
  129. }
  130. let inputWithAddonProperty = ComponentInputWithAddonProperty(size: inputWithSize,
  131. isDisabled: self.inputWithAddonDisableBtn.state == .on,
  132. addonType: inputWithType)
  133. self.inputWithAddon.properties = inputWithAddonProperty
  134. self.inputWithAddonHeightConst.constant = self.inputWithAddon.properties.propertyInfo.viewHeight
  135. }
  136. @IBAction func buttonAction(_ sender: Any) {
  137. self.reloadData()
  138. }
  139. @objc func addOnItemClick(_ sender: Any) {
  140. }
  141. override func mouseDown(with event: NSEvent) {
  142. super.mouseDown(with: event)
  143. self.view.window?.makeFirstResponder(nil)
  144. }
  145. }