// // TooltipVC.swift // KMComponentLibrary // // Created by Niehaoyu on 2024/9/10. // import Cocoa import KMComponentLibrary class TooltipVC: NSViewController { @IBOutlet weak var tooltipItem: ComponentToolTip! @IBOutlet weak var typeBox: NSComboBox! @IBOutlet weak var titleField: NSTextField! @IBOutlet weak var subTitleField: NSTextField! override func viewDidLoad() { super.viewDidLoad() // Do view setup here. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: subTitleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: subTitleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: subTitleField) self.typeBox.selectItem(at: 0) self.reloadData() } func reloadData() { let type: ComponentPositionType = ComponentPositionType(rawValue: self.typeBox.indexOfSelectedItem) ?? .left_Top //progressItem let properties: ComponentTooltipProperty = ComponentTooltipProperty(arrowPosition: type, title: self.titleField.stringValue, infoString: self.subTitleField.stringValue) self.tooltipItem.properties = properties } @IBAction func typeAction(_ 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() } }