ASSizePropertyCell.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // ASIntPropertyCell.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2023/4/17.
  6. //
  7. import Cocoa
  8. class ASSizePropertyCell: ASPropertyCell, NSTextFieldDelegate {
  9. @IBOutlet var m_titleLbl:NSTextField!
  10. @IBOutlet var m_wTF:NSTextField!
  11. @IBOutlet var m_hTF:NSTextField!
  12. override class func shared() -> ASPropertyCell? {
  13. var objects : NSArray!
  14. Bundle.main.loadNibNamed("ASSizePropertyCell", owner: nil, topLevelObjects: &objects)
  15. for tView in objects {
  16. if let tv = tView as? ASSizePropertyCell {
  17. return tv
  18. }
  19. }
  20. return nil
  21. }
  22. /// Setter
  23. override func setPropertyInfo(_ info:NSDictionary) {
  24. super.setPropertyInfo(info)
  25. self.m_titleLbl.stringValue = "\(info.value(forKey: "Name") ?? ""):"
  26. setValue((info.value(forKey: "DefaultValue") ?? "0") as AnyObject)
  27. }
  28. override func setValue(_ value:AnyObject) {
  29. super.setValue(value)
  30. if (value as? String) != nil {
  31. let sizeString = value as! String
  32. let size = NSSizeFromString(sizeString);
  33. self.m_wTF.stringValue = "\(size.width)";
  34. self.m_hTF.stringValue = "\(size.height)";
  35. }
  36. }
  37. override func value() -> AnyObject {
  38. let size = CGSizeMake(CGFloat(NSString(string: self.m_wTF.stringValue).floatValue),
  39. CGFloat(NSString(string: self.m_hTF.stringValue).floatValue))
  40. return NSStringFromSize(size) as AnyObject
  41. }
  42. override func setEnabled(_ enabled:Bool) {
  43. super.setEnabled(enabled)
  44. self.alphaValue = enabled ? 1 : 0.6
  45. self.m_wTF.isEnabled = enabled;
  46. self.m_hTF.isEnabled = enabled;
  47. }
  48. }