123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // InputNumberVC.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2024/8/27.
- //
- import Cocoa
- import KMComponentLibrary
- class InputNumberVC: NSViewController, NSTextFieldDelegate {
- @IBOutlet weak var inputNumberView: ComponentInputNumber!
- @IBOutlet weak var sizeBox: NSComboBox!
- @IBOutlet weak var errorBtn: NSButton!
- @IBOutlet weak var disableButton: NSButton!
- @IBOutlet weak var prefixBtn: NSButton!
- @IBOutlet weak var suffixButton: NSButton!
- @IBOutlet weak var showErrorBtn: NSButton!
- @IBOutlet weak var isCenterBtn: NSButton!
-
- @IBOutlet weak var minSizeField: NSTextField!
- @IBOutlet weak var maxSizeField: NSTextField!
-
-
- @IBOutlet weak var viewheightConst: NSLayoutConstraint!
-
- let properties: ComponentInputNumberProperty = ComponentInputNumberProperty.init(alignment: .left, size: .m, state: .normal, isError: false)
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self.minSizeField.intValue = 0
- self.maxSizeField.intValue = 10
-
- inputNumberView.delegate = self
-
- self.minSizeField.delegate = self
- self.maxSizeField.delegate = self
-
- self.configSizeValue()
-
- self.reloadData()
- }
-
- func reloadData() {
- if self.sizeBox.indexOfSelectedItem == 0 {
- properties.size = .m
- } else {
- properties.size = .s
- }
- properties.isDisabled = self.disableButton.state == .on
- properties.showPrefix = self.prefixBtn.state == .on
- properties.showSuffix = self.suffixButton.state == .on
- if self.isCenterBtn.state == .on {
- properties.alignment = .center
- } else {
- properties.alignment = .left
- }
-
- var minSize = self.minSizeField.intValue
-
- var maxSize = self.maxSizeField.intValue
-
- if maxSize < 0 {
- maxSize = 50
- }
-
- if minSize > maxSize {
- minSize = 0
- }
-
- self.minSizeField.stringValue = String(minSize)
- self.maxSizeField.stringValue = String(maxSize)
-
- properties.minSize = Int(minSize)
- properties.maxSize = Int(maxSize)
-
-
- inputNumberView.properties = properties
-
- self.viewheightConst.constant = properties.propertyInfo.viewHeight
- }
-
- @IBAction func sizeAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func disableAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func prefixAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func suffixAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func isCenterAction(_ sender: Any) {
- self.reloadData()
- }
-
-
- func configSizeValue() {
- self.reloadData()
- }
-
-
- override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
-
- self.view.window?.makeFirstResponder(nil)
- }
-
-
- func controlTextDidBeginEditing(_ obj: Notification) {
- self.configSizeValue()
- }
-
- func controlTextDidEndEditing(_ obj: Notification) {
- self.configSizeValue()
- }
- }
- extension InputNumberVC: ComponentInputNumberDelegate {
- func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
-
- self.viewheightConst.constant = properties.propertyInfo.viewHeight
-
- }
- }
|