123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // CheckBoxVC.swift
- // KMComponentLibrary
- //
- // Created by Niehaoyu on 2024/8/29.
- //
- import Cocoa
- import KMComponentLibrary
- class CheckBoxVC: NSViewController {
- @IBOutlet weak var checkBox: ComponentCheckBox!
- @IBOutlet weak var radio: ComponentRadio!
-
- @IBOutlet weak var typeBox: NSComboBox!
- @IBOutlet weak var sizeBox: NSComboBox!
- @IBOutlet weak var disableButton: NSButton!
- @IBOutlet weak var showLabelBtn: NSButton!
- @IBOutlet weak var showHelpButton: NSButton!
- @IBOutlet weak var inputField: NSTextField!
- @IBOutlet weak var indeteBtn: NSButton!
-
- @IBOutlet weak var checkBoxWidthConst: NSLayoutConstraint!
- @IBOutlet weak var checkBoxHeightConst: NSLayoutConstraint!
-
- @IBOutlet weak var radioWidthConst: NSLayoutConstraint!
- @IBOutlet weak var radioHeightConst: NSLayoutConstraint!
-
-
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self.typeBox.selectItem(at: 0)
-
-
- NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: inputField)
- NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: inputField)
- NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: inputField)
-
-
- self.reloadData()
-
- }
-
- func reloadData() {
- self.checkBox.isHidden = true
- self.radio.isHidden = true
-
- self.indeteBtn.isEnabled = true
-
- if self.typeBox.indexOfSelectedItem == 0 {
- self.checkBox.isHidden = false
- self.indeteBtn.isEnabled = false
- } else if self.typeBox.indexOfSelectedItem == 1 {
- self.radio.isHidden = false
- }
-
-
- var size: ComponentSize = .m
- if self.sizeBox.indexOfSelectedItem == 0 {
- size = .m
- } else if self.sizeBox.indexOfSelectedItem == 1 {
- size = .s
- } else if self.sizeBox.indexOfSelectedItem == 2 {
- size = .xs
- } else if self.sizeBox.indexOfSelectedItem == 3 {
- size = .xxs
- }
-
- let isDisabel = self.disableButton.state == .on
- let showlabel = self.showLabelBtn.state == .on
- let showhelp = self.showHelpButton.state == .on
- let string = self.inputField.stringValue
-
- var checkboxType: componentCheckboxType = .normal
- if self.indeteBtn.state == .on {
- checkboxType = .indeterminate
- }
-
- let properties: ComponentCheckBoxProperty = ComponentCheckBoxProperty.init(size: size, state: .normal, isDisabled: isDisabel, showhelp: showhelp, text: string, checkboxType: checkboxType)
- checkBox.toolTip = "12312312312312"
- checkBox.properties = properties
-
-
- let radioproperties: ComponentCheckBoxProperty = ComponentCheckBoxProperty.init(size: size, state: .normal, isDisabled: isDisabel, showhelp: showhelp, text: string, checkboxType: checkboxType)
- radio.properties = radioproperties
-
- self.checkBoxWidthConst.constant = checkBox.properties.propertyInfo.viewWidth
- self.checkBoxHeightConst.constant = checkBox.properties.propertyInfo.viewHeight
-
- self.radioWidthConst.constant = radio.properties.propertyInfo.viewWidth
- self.radioHeightConst.constant = radio.properties.propertyInfo.viewHeight
-
- }
-
- @IBAction func clickAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func sizeBoxAction(_ sender: Any) {
- self.reloadData()
- }
-
- //MARK: - TextNotification
- @objc func textFieldDidBeginEditingNotification(_ notification: Notification) {
- print("textFieldDidBeginEditingNotification")
-
- }
-
- @objc func textFieldDidChangeNotification(_ notification: Notification) {
- print("textFieldDidChangeNotification")
-
- self.reloadData()
- }
-
- @objc func textFieldDidEndEditingNotification(_ notification: Notification) {
- print("textFieldDidEndEditingNotification")
-
- self.reloadData()
- }
-
-
- }
|