|
@@ -12,6 +12,7 @@ import Cocoa
|
|
|
case Image
|
|
|
case TextImage
|
|
|
case PopUpButton
|
|
|
+ case RadioButton
|
|
|
}
|
|
|
|
|
|
class KMDesignButton: KMDesignBase {
|
|
@@ -58,19 +59,28 @@ class KMDesignButton: KMDesignBase {
|
|
|
@IBOutlet weak var textImage_rightImageWidth: NSLayoutConstraint!
|
|
|
@IBOutlet weak var textImage_rightItem_spacing: NSLayoutConstraint!
|
|
|
|
|
|
+ @IBOutlet weak var radioButton_mainBox: NSBox!
|
|
|
+ @IBOutlet weak var radioButton_imageView: NSImageView!
|
|
|
+ @IBOutlet weak var radioButton_label: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var radio_label_spacing: NSLayoutConstraint!
|
|
|
+ @IBOutlet weak var radio_imageViewWidth: NSLayoutConstraint!
|
|
|
+ @IBOutlet weak var radio_imageViewHeight: NSLayoutConstraint!
|
|
|
+
|
|
|
@IBOutlet weak var mainBoxHeight : NSLayoutConstraint! // mainBox 高度约束
|
|
|
@IBOutlet weak var mainBoxWidth : NSLayoutConstraint! // mainBox 宽度约束
|
|
|
var height: Float = 32.0 // 高度
|
|
|
var width: Float = 80.0 // 宽度
|
|
|
|
|
|
- var _image: NSImage = NSImage(named: "KMFileIcon")!
|
|
|
- var image_hov: NSImage = NSImage(named: "KMFileIcon")!
|
|
|
- var image_act: NSImage = NSImage(named: "KMFileIcon")!
|
|
|
- var image_disabled: NSImage = NSImage(named: "KMFileIcon")!
|
|
|
var textImage_imageWidth: Float = 20.0// 图片宽度
|
|
|
var textImage_imageHeight: Float = 20.0// 图片高度
|
|
|
var textImage_paddingSpacing: Float = 16.0
|
|
|
var textImage_itemSpacing: Float = 8.0
|
|
|
+
|
|
|
+// var image: NSImage = NSImage(named: "KMRadioButtonUnSelect")! // imageView 图片
|
|
|
+ var radio_imageWidth = 16.0 // 图片宽度
|
|
|
+ var radio_imageHeight = 16.0 // 图片高度
|
|
|
+ var radio_label = 8.0 // imageView、label 水平间距
|
|
|
|
|
|
// button 通用属性
|
|
|
var textImage_type: KMTextImageButtonType = .Left
|
|
@@ -97,6 +107,8 @@ class KMDesignButton: KMDesignBase {
|
|
|
mainBox.contentView = textImageButtonBox
|
|
|
} else if (buttonType == .PopUpButton) {
|
|
|
mainBox.contentView = textImageButtonBox
|
|
|
+ } else if (buttonType == .RadioButton) {
|
|
|
+ mainBox.contentView = radioButton_mainBox
|
|
|
}
|
|
|
|
|
|
textButtonBox.move = { [self](mouseEntered: Bool) -> Void in
|
|
@@ -204,19 +216,59 @@ class KMDesignButton: KMDesignBase {
|
|
|
set {
|
|
|
_image = newValue
|
|
|
|
|
|
- if (buttonType == .Image) {
|
|
|
- imageView1.image = _image
|
|
|
- } else if (buttonType == .TextImage) {
|
|
|
- if textImage_type == .Up {
|
|
|
- textImage_upImageView.image = image
|
|
|
- } else if textImage_type == .Left {
|
|
|
- textImage_leftImageView.image = image
|
|
|
- } else if textImage_type == .Down {
|
|
|
- textImage_downImageView.image = image
|
|
|
- } else if textImage_type == .Right {
|
|
|
- textImage_rightImageView.image = image
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var image_hov: NSImage {
|
|
|
+ get {
|
|
|
+ if _image_hov == nil {
|
|
|
+ return _image
|
|
|
+ }
|
|
|
+ return _image_hov!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _image_hov = newValue
|
|
|
+ updateUI()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var image_act: NSImage {
|
|
|
+ get {
|
|
|
+ if _image_act == nil {
|
|
|
+ return _image
|
|
|
+ }
|
|
|
+ return _image_act!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _image_act = newValue
|
|
|
+ updateUI()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var image_disabled: NSImage {
|
|
|
+ get {
|
|
|
+ if _image_disabled == nil {
|
|
|
+ return _image
|
|
|
}
|
|
|
+ return _image_disabled!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _image_disabled = newValue
|
|
|
+ updateUI()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var image_sel: NSImage {
|
|
|
+ get {
|
|
|
+ if (_image_sel == nil) {
|
|
|
+ _image_sel = image
|
|
|
+ }
|
|
|
+ return _image_sel!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _image_sel = newValue
|
|
|
+ updateUI()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -277,21 +329,25 @@ class KMDesignButton: KMDesignBase {
|
|
|
imageButtonBox.borderWidth = CGFloat(borderWidth)
|
|
|
imageButtonBox.borderColor = borderColor
|
|
|
imageButtonBox.cornerRadius = CGFloat(cornerRadius)
|
|
|
+ imageView1.image = image
|
|
|
} else if (state == .Hov) {
|
|
|
imageButtonBox.fillColor = background_hov
|
|
|
imageButtonBox.borderWidth = CGFloat(borderWidth_hov)
|
|
|
imageButtonBox.borderColor = borderColor_hov
|
|
|
imageButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
|
|
|
+ imageView1.image = image_hov
|
|
|
} else if (state == .Act) {
|
|
|
imageButtonBox.fillColor = background_act
|
|
|
imageButtonBox.borderWidth = CGFloat(borderWidth_act)
|
|
|
imageButtonBox.borderColor = borderColor_act
|
|
|
imageButtonBox.cornerRadius = CGFloat(cornerRadius_act)
|
|
|
+ imageView1.image = image_act
|
|
|
} else if (state == .Disabled) {
|
|
|
imageButtonBox.fillColor = background_disabled
|
|
|
imageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
|
|
|
imageButtonBox.borderColor = borderColor_disabled
|
|
|
imageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
|
|
|
+ imageView1.image = image_disabled
|
|
|
}
|
|
|
} else if (buttonType == .TextImage) {
|
|
|
let paragraphStyle = NSMutableParagraphStyle()
|
|
@@ -329,6 +385,7 @@ class KMDesignButton: KMDesignBase {
|
|
|
textImage_rightImageView.image = image
|
|
|
textImage_rightTextfield.textColor = textColor
|
|
|
}
|
|
|
+
|
|
|
textImageButtonBox.borderWidth = CGFloat(borderWidth)
|
|
|
textImageButtonBox.cornerRadius = CGFloat(cornerRadius)
|
|
|
paragraphStyle.lineSpacing = lineHeight
|
|
@@ -336,16 +393,16 @@ class KMDesignButton: KMDesignBase {
|
|
|
textImageButtonBox.fillColor = background_hov
|
|
|
textImageButtonBox.borderColor = borderColor_hov
|
|
|
if textImage_type == .Up {
|
|
|
- textImage_upImageView.image = image
|
|
|
+ textImage_upImageView.image = image_hov
|
|
|
textImage_upTextfield.textColor = textColor_hov
|
|
|
} else if textImage_type == .Left {
|
|
|
- textImage_leftImageView.image = image
|
|
|
+ textImage_leftImageView.image = image_hov
|
|
|
textImage_leftTextfield.textColor = textColor_hov
|
|
|
} else if textImage_type == .Down {
|
|
|
- textImage_downImageView.image = image
|
|
|
+ textImage_downImageView.image = image_hov
|
|
|
textImage_downTextfield.textColor = textColor_hov
|
|
|
} else if textImage_type == .Right {
|
|
|
- textImage_rightImageView.image = image
|
|
|
+ textImage_rightImageView.image = image_hov
|
|
|
textImage_rightTextfield.textColor = textColor_hov
|
|
|
}
|
|
|
textImageButtonBox.borderWidth = CGFloat(borderWidth_hov)
|
|
@@ -355,16 +412,16 @@ class KMDesignButton: KMDesignBase {
|
|
|
textImageButtonBox.fillColor = background_act
|
|
|
textImageButtonBox.borderColor = borderColor_act
|
|
|
if textImage_type == .Up {
|
|
|
- textImage_upImageView.image = image
|
|
|
+ textImage_upImageView.image = image_act
|
|
|
textImage_upTextfield.textColor = textColor_act
|
|
|
} else if textImage_type == .Left {
|
|
|
- textImage_leftImageView.image = image
|
|
|
+ textImage_leftImageView.image = image_act
|
|
|
textImage_leftTextfield.textColor = textColor_act
|
|
|
} else if textImage_type == .Down {
|
|
|
- textImage_downImageView.image = image
|
|
|
+ textImage_downImageView.image = image_act
|
|
|
textImage_downTextfield.textColor = textColor_act
|
|
|
} else if textImage_type == .Right {
|
|
|
- textImage_rightImageView.image = image
|
|
|
+ textImage_rightImageView.image = image_act
|
|
|
textImage_rightTextfield.textColor = textColor_act
|
|
|
}
|
|
|
textImageButtonBox.borderWidth = CGFloat(borderWidth_act)
|
|
@@ -374,16 +431,16 @@ class KMDesignButton: KMDesignBase {
|
|
|
textImageButtonBox.fillColor = background_disabled
|
|
|
textImageButtonBox.borderColor = borderColor_disabled
|
|
|
if textImage_type == .Up {
|
|
|
- textImage_upImageView.image = image
|
|
|
+ textImage_upImageView.image = image_disabled
|
|
|
textImage_upTextfield.textColor = textColor_disabled
|
|
|
} else if textImage_type == .Left {
|
|
|
- textImage_leftImageView.image = image
|
|
|
+ textImage_leftImageView.image = image_disabled
|
|
|
textImage_leftTextfield.textColor = textColor_disabled
|
|
|
} else if textImage_type == .Down {
|
|
|
- textImage_downImageView.image = image
|
|
|
+ textImage_downImageView.image = image_disabled
|
|
|
textImage_downTextfield.textColor = textColor_disabled
|
|
|
} else if textImage_type == .Right {
|
|
|
- textImage_rightImageView.image = image
|
|
|
+ textImage_rightImageView.image = image_disabled
|
|
|
textImage_rightTextfield.textColor = textColor_disabled
|
|
|
}
|
|
|
textImageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
|
|
@@ -417,6 +474,35 @@ class KMDesignButton: KMDesignBase {
|
|
|
textImage_rightPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
|
|
|
textImage_rightItem_spacing.constant = CGFloat(textImage_itemSpacing)
|
|
|
}
|
|
|
+ } else if (buttonType == .RadioButton) {
|
|
|
+ let paragraphStyle = NSMutableParagraphStyle()
|
|
|
+ if (state == .Norm) {
|
|
|
+ radioButton_imageView.image = image
|
|
|
+ radioButton_label.font = font
|
|
|
+ radioButton_label.textColor = textColor
|
|
|
+ paragraphStyle.lineSpacing = lineHeight
|
|
|
+ } else if (state == .Hov) {
|
|
|
+ radioButton_imageView.image = image_hov
|
|
|
+ radioButton_label.font = font_hov
|
|
|
+ radioButton_label.textColor = textColor_hov
|
|
|
+ paragraphStyle.lineSpacing = lineHeight_hov
|
|
|
+ } else if (state == .Sel) {
|
|
|
+ radioButton_imageView.image = image_sel
|
|
|
+ radioButton_label.font = font_sel
|
|
|
+ radioButton_label.textColor = textColor_sel
|
|
|
+ paragraphStyle.lineSpacing = lineHeight_sel
|
|
|
+ } else if (state == .Disabled) {
|
|
|
+ radioButton_imageView.image = image_disabled
|
|
|
+ radioButton_label.font = font_disabled
|
|
|
+ radioButton_label.textColor = textColor_disabled
|
|
|
+ paragraphStyle.lineSpacing = lineHeight_disabled
|
|
|
+ }
|
|
|
+ radioButton_label.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
+
|
|
|
+
|
|
|
+ radio_label_spacing.constant = radio_label
|
|
|
+ radio_imageViewWidth.constant = radio_imageWidth
|
|
|
+ radio_imageViewHeight.constant = radio_imageHeight
|
|
|
}
|
|
|
}
|
|
|
}
|