SelectVC.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // SelectVC.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/9/3.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class SelectVC: NSViewController {
  10. @IBOutlet weak var selectItemView: ComponentSelect!
  11. @IBOutlet weak var selectZoom: ComponentSelectZoom!
  12. @IBOutlet weak var sizeBox: NSComboBox!
  13. @IBOutlet weak var disableBtn: NSButton!
  14. @IBOutlet weak var errorBtn: NSButton!
  15. @IBOutlet weak var showLeftIcon: NSButton!
  16. @IBOutlet weak var placeholderField: NSTextField!
  17. @IBOutlet weak var errorField: NSTextField!
  18. @IBOutlet weak var createableBtn: NSButton!
  19. @IBOutlet weak var itemheightConst: NSLayoutConstraint!
  20. @IBOutlet weak var zoomDisableBtn: NSButton!
  21. var groupView: ComponentGroup!
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. // Do view setup here.
  25. self.sizeBox.selectItem(at: 0)
  26. self.reloadData()
  27. }
  28. func reloadData() {
  29. var size: ComponentSize = .m
  30. if self.sizeBox.indexOfSelectedItem == 0 {
  31. size = .m
  32. } else if self.sizeBox.indexOfSelectedItem == 1 {
  33. size = .s
  34. } else if self.sizeBox.indexOfSelectedItem == 2 {
  35. size = .xs
  36. } else if self.sizeBox.indexOfSelectedItem == 3 {
  37. size = .xxs
  38. }
  39. let disable = self.disableBtn.state == .on
  40. let isError = self.errorBtn.state == .on
  41. let lefticon = self.showLeftIcon.state == .on
  42. let placeholder = self.placeholderField.stringValue
  43. let errorText = self.errorField.stringValue
  44. let properties: ComponentSelectProperties = ComponentSelectProperties.init(size: size,
  45. state: .normal,
  46. isDisabled: disable,
  47. isError: isError,
  48. leftIcon: lefticon,
  49. placeholder: placeholder,
  50. errorText: errorText,
  51. creatable: self.createableBtn.state == .on)
  52. selectItemView.properties = properties
  53. self.itemheightConst.constant = selectItemView.properties.propertyInfo.viewHeight
  54. var menuItemArr: [ComponentMenuitemProperty] = []
  55. for i in 0...5 {
  56. let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "menu item - " + String(i))
  57. menuItemArr.append(properties_Menuitem)
  58. }
  59. selectItemView.updateMenuItemsArr(menuItemArr)
  60. selectZoom.properties = ComponentSelectZoomProperty(state: .normal,
  61. isDisabled: zoomDisableBtn.state == .on,
  62. text: "100")
  63. }
  64. @IBAction func boxAction(_ sender: Any) {
  65. self.reloadData()
  66. }
  67. @IBAction func btnAction(_ sender: Any) {
  68. self.reloadData()
  69. }
  70. }