KMDesignButton.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. //
  2. // KMDesignButton.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2023/2/18.
  6. //
  7. import Cocoa
  8. @objc enum DesignButtonType : Int {
  9. case Text = 0 // 纯文本按钮
  10. case Image // 纯图片按钮
  11. case TextImage // 文本+图片按钮,区分图片在上左下右位置
  12. case PopUpButton // PopUp按钮
  13. case RadioButton // 单选按钮
  14. case CheckBox // 多选按钮
  15. }
  16. @objcMembers class KMDesignButton: KMDesignBase {
  17. @IBOutlet weak var mainBox: NSBox!
  18. @IBOutlet weak var button : NSButton!
  19. // Text
  20. @IBOutlet weak var textButtonBox: KMMoveBox!
  21. @IBOutlet weak var textButtonlabel : NSTextField!
  22. // Image
  23. @IBOutlet weak var imageButtonBox: KMMoveBox!
  24. @IBOutlet weak var imageView1: NSImageView!
  25. // TextImage
  26. @IBOutlet weak var textImageButtonBox: KMMoveBox!
  27. @IBOutlet weak var textImage_upView: NSView!
  28. @IBOutlet weak var textImage_leftView: NSView!
  29. @IBOutlet weak var textImage_downView: NSView!
  30. @IBOutlet weak var textImage_rightView: NSView!
  31. @IBOutlet weak var textImage_upImageView: NSImageView!
  32. @IBOutlet weak var textImage_leftImageView: NSImageView!
  33. @IBOutlet weak var textImage_downImageView: NSImageView!
  34. @IBOutlet weak var textImage_rightImageView: NSImageView!
  35. @IBOutlet weak var textImage_upTextfield: NSTextField!
  36. @IBOutlet weak var textImage_leftTextfield: NSTextField!
  37. @IBOutlet weak var textImage_downTextfield: NSTextField!
  38. @IBOutlet weak var textImage_rightTextfield: NSTextField!
  39. @IBOutlet weak var textImage_upPadding_spacing: NSLayoutConstraint!
  40. @IBOutlet weak var textImage_upImageHeight: NSLayoutConstraint!
  41. @IBOutlet weak var textImage_upImageWidth: NSLayoutConstraint!
  42. @IBOutlet weak var textImage_upItem_spacing: NSLayoutConstraint!
  43. @IBOutlet weak var textImage_leftPadding_spacing: NSLayoutConstraint!
  44. @IBOutlet weak var textImage_leftImageHeight: NSLayoutConstraint!
  45. @IBOutlet weak var textImage_leftImageWidth: NSLayoutConstraint!
  46. @IBOutlet weak var textImage_leftItem_spacing: NSLayoutConstraint!
  47. @IBOutlet weak var textImage_downPadding_spacing: NSLayoutConstraint!
  48. @IBOutlet weak var textImage_downImageHeight: NSLayoutConstraint!
  49. @IBOutlet weak var textImage_downImageWidth: NSLayoutConstraint!
  50. @IBOutlet weak var textImage_downItem_spacing: NSLayoutConstraint!
  51. @IBOutlet weak var textImage_rightPadding_spacing: NSLayoutConstraint!
  52. @IBOutlet weak var textImage_rightImageHeight: NSLayoutConstraint!
  53. @IBOutlet weak var textImage_rightImageWidth: NSLayoutConstraint!
  54. @IBOutlet weak var textImage_rightItem_spacing: NSLayoutConstraint!
  55. @IBOutlet weak var radioButton_mainBox: KMMoveBox!
  56. @IBOutlet weak var radioButton_imageView: NSImageView!
  57. @IBOutlet weak var radioButton_label: NSTextField!
  58. @IBOutlet weak var radio_label_spacing: NSLayoutConstraint!
  59. @IBOutlet weak var radio_imageViewWidth: NSLayoutConstraint!
  60. @IBOutlet weak var radio_imageViewHeight: NSLayoutConstraint!
  61. @IBOutlet weak var mainBoxHeight : NSLayoutConstraint! // mainBox 高度约束
  62. @IBOutlet weak var mainBoxWidth : NSLayoutConstraint! // mainBox 宽度约束
  63. var height: Float = 32.0 // 高度
  64. var width: Float = 80.0 // 宽度
  65. var textImage_imageWidth: Float = 20.0// 图片宽度
  66. var textImage_imageHeight: Float = 20.0// 图片高度
  67. var textImage_paddingSpacing: Float = 16.0
  68. var textImage_itemSpacing: Float = 8.0
  69. // var image: NSImage = NSImage(named: "KMRadioButtonUnSelect")! // imageView 图片
  70. var radio_imageWidth = 16.0 // 图片宽度
  71. var radio_imageHeight = 16.0 // 图片高度
  72. var radio_label = 8.0 // imageView、label 水平间距
  73. // button 通用属性
  74. var textImage_type: KMTextImageButtonType = .Left
  75. var textImage_state: KMDesignTokenState = .Norm
  76. var ignoreDisabledImage = false
  77. var tag: Int = 0 {
  78. didSet {
  79. self.button.tag = self.tag
  80. }
  81. }
  82. init(withType type: DesignButtonType) {
  83. super.init(nibName: "KMDesignButton", bundle: nil)
  84. self.buttonType = type
  85. }
  86. required init?(coder: NSCoder) {
  87. fatalError("init(coder:) has not been implemented")
  88. }
  89. override func viewDidLoad() {
  90. super.viewDidLoad()
  91. // Do view setup here.
  92. if (buttonType == .Text) {
  93. mainBox.contentView = textButtonBox
  94. } else if (buttonType == .Image) {
  95. mainBox.contentView = imageButtonBox
  96. } else if (buttonType == .TextImage) {
  97. mainBox.contentView = textImageButtonBox
  98. } else if (buttonType == .PopUpButton) {
  99. mainBox.contentView = textImageButtonBox
  100. } else if (buttonType == .RadioButton) || (buttonType == .CheckBox) {
  101. mainBox.contentView = radioButton_mainBox
  102. }
  103. textButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  104. if self != nil {
  105. if mouseEntered {
  106. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  107. self!.state = .Hov
  108. self!.updateUI()
  109. }
  110. } else {
  111. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  112. self!.state = .Norm
  113. self!.updateUI()
  114. }
  115. }
  116. }
  117. }
  118. imageButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  119. if self != nil {
  120. if mouseEntered {
  121. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  122. self!.state = .Hov
  123. self!.updateUI()
  124. }
  125. } else {
  126. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  127. self!.state = .Norm
  128. self!.updateUI()
  129. }
  130. }
  131. }
  132. }
  133. textImageButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  134. if self != nil {
  135. if mouseEntered {
  136. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  137. self!.state = .Hov
  138. self!.updateUI()
  139. }
  140. } else {
  141. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  142. self!.state = .Norm
  143. self!.updateUI()
  144. }
  145. }
  146. }
  147. }
  148. radioButton_mainBox.move = { [weak self](mouseEntered: Bool) -> Void in
  149. if self != nil {
  150. if mouseEntered {
  151. if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  152. self!.state = .Hov
  153. self!.updateUI()
  154. }
  155. } else {
  156. if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  157. self!.state = .Norm
  158. self!.updateUI()
  159. }
  160. }
  161. }
  162. }
  163. // self.radioButton_mainBox.canHover = true
  164. // self.radioButton_mainBox.canClick = true
  165. // radioButton_mainBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox) -> Void in
  166. // if self != nil {
  167. // if self!.enabled {
  168. // if downEntered {
  169. // self!.canHover = false
  170. // self!.state = .Checked
  171. // self!.updateUI()
  172. // }
  173. // }
  174. // }
  175. // }
  176. // radioButton_mainBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  177. // if self != nil {
  178. // if mouseEntered {
  179. // if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  180. // self!.state = .Hov
  181. // self!.updateUI()
  182. // }
  183. // } else {
  184. // if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  185. // self!.state = .Norm
  186. // self!.updateUI()
  187. // }
  188. // }
  189. // }
  190. // }
  191. }
  192. // MARK: Get、Set
  193. var action: Selector {
  194. get {
  195. return _action!
  196. }
  197. set {
  198. _action = newValue
  199. if _action != nil {
  200. button.action = _action
  201. }
  202. }
  203. }
  204. var target: AnyObject {
  205. get {
  206. return _target!
  207. }
  208. set {
  209. _target = newValue
  210. if _target != nil {
  211. button.target = _target
  212. }
  213. }
  214. }
  215. var state: KMDesignTokenState {
  216. get {
  217. return _state
  218. }
  219. set {
  220. _state = newValue
  221. updateUI()
  222. }
  223. }
  224. var enabled: Bool {
  225. get {
  226. return _enabled
  227. }
  228. set {
  229. _enabled = newValue
  230. self.button.isEnabled = _enabled
  231. if _enabled {
  232. state = .Norm
  233. } else {
  234. state = .Disabled
  235. }
  236. updateUI()
  237. }
  238. }
  239. var isHidden: Bool {
  240. get {
  241. return _isHidden
  242. }
  243. set {
  244. _isHidden = newValue
  245. self.view.isHidden = _isHidden
  246. }
  247. }
  248. var image: NSImage {
  249. get {
  250. return _image
  251. }
  252. set {
  253. _image = newValue
  254. updateUI()
  255. }
  256. }
  257. var image_hov: NSImage {
  258. get {
  259. if _image_hov == nil {
  260. return _image
  261. }
  262. return _image_hov!
  263. }
  264. set {
  265. _image_hov = newValue
  266. updateUI()
  267. }
  268. }
  269. var image_act: NSImage {
  270. get {
  271. if _image_act == nil {
  272. return _image
  273. }
  274. return _image_act!
  275. }
  276. set {
  277. _image_act = newValue
  278. updateUI()
  279. }
  280. }
  281. var image_disabled: NSImage {
  282. get {
  283. if self.ignoreDisabledImage {
  284. return _image
  285. }
  286. if _image_disabled == nil {
  287. return _image
  288. }
  289. return _image_disabled!
  290. }
  291. set {
  292. _image_disabled = newValue
  293. updateUI()
  294. }
  295. }
  296. var image_sel: NSImage {
  297. get {
  298. if (_image_sel == nil) {
  299. _image_sel = image
  300. }
  301. return _image_sel!
  302. }
  303. set {
  304. _image_sel = newValue
  305. updateUI()
  306. }
  307. }
  308. var image_checked: NSImage {
  309. get {
  310. if (_image_checked == nil) {
  311. _image_checked = image
  312. }
  313. return _image_checked!
  314. }
  315. set {
  316. _image_checked = newValue
  317. updateUI()
  318. }
  319. }
  320. var image_checkeddis: NSImage {
  321. get {
  322. if (_image_checkeddis == nil) {
  323. _image_checkeddis = image
  324. }
  325. return _image_checkeddis!
  326. }
  327. set {
  328. _image_checkeddis = newValue
  329. updateUI()
  330. }
  331. }
  332. var toolTip: String {
  333. get {
  334. return _toolTip
  335. }
  336. set {
  337. _toolTip = newValue
  338. if _toolTip != "" {
  339. button.toolTip = _toolTip
  340. }
  341. }
  342. }
  343. // MARK: Private Methods
  344. func updateUI() -> Void {
  345. if (buttonType == .Text) {
  346. let paragraphStyle = NSMutableParagraphStyle()
  347. if (state == .Norm) {
  348. textButtonBox.fillColor = background
  349. textButtonBox.borderWidth = CGFloat(borderWidth)
  350. textButtonBox.cornerRadius = CGFloat(cornerRadius)
  351. textButtonBox.borderColor = borderColor
  352. textButtonlabel.textColor = textColor
  353. textButtonlabel.font = font
  354. paragraphStyle.lineSpacing = lineHeight
  355. } else if (state == .Hov) {
  356. textButtonBox.fillColor = background_hov
  357. textButtonBox.borderWidth = CGFloat(borderWidth_hov)
  358. textButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  359. textButtonBox.borderColor = borderColor_hov
  360. textButtonlabel.textColor = textColor_hov
  361. textButtonlabel.font = font_hov
  362. paragraphStyle.lineSpacing = lineHeight_hov
  363. } else if (state == .Act) {
  364. textButtonBox.fillColor = background_act
  365. textButtonBox.borderWidth = CGFloat(borderWidth_act)
  366. textButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  367. textButtonBox.borderColor = borderColor_act
  368. textButtonlabel.textColor = textColor_act
  369. textButtonlabel.font = font_act
  370. paragraphStyle.lineSpacing = lineHeight_act
  371. } else if (state == .Disabled) {
  372. textButtonBox.fillColor = background_disabled
  373. textButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  374. textButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  375. textButtonBox.borderColor = borderColor_disabled
  376. textButtonlabel.textColor = textColor_disabled
  377. textButtonlabel.font = font_disabled
  378. paragraphStyle.lineSpacing = lineHeight_disabled
  379. }
  380. textButtonlabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  381. } else if (buttonType == .Image) {
  382. if (state == .Norm) {
  383. imageButtonBox.fillColor = background
  384. imageButtonBox.borderWidth = CGFloat(borderWidth)
  385. imageButtonBox.borderColor = borderColor
  386. imageButtonBox.cornerRadius = CGFloat(cornerRadius)
  387. imageView1.image = image
  388. } else if (state == .Hov) {
  389. imageButtonBox.fillColor = background_hov
  390. imageButtonBox.borderWidth = CGFloat(borderWidth_hov)
  391. imageButtonBox.borderColor = borderColor_hov
  392. imageButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  393. imageView1.image = image_hov
  394. } else if (state == .Act) {
  395. imageButtonBox.fillColor = background_act
  396. imageButtonBox.borderWidth = CGFloat(borderWidth_act)
  397. imageButtonBox.borderColor = borderColor_act
  398. imageButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  399. imageView1.image = image_act
  400. } else if (state == .Disabled) {
  401. imageButtonBox.fillColor = background_disabled
  402. imageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  403. imageButtonBox.borderColor = borderColor_disabled
  404. imageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  405. imageView1.image = image_disabled
  406. }
  407. } else if (buttonType == .TextImage) {
  408. let paragraphStyle = NSMutableParagraphStyle()
  409. if textImage_type == .Up {
  410. textImageButtonBox.contentView = textImage_upView
  411. textImage_upTextfield.isEditable = editable
  412. textImage_upTextfield.font = font
  413. } else if textImage_type == .Left {
  414. textImageButtonBox.contentView = textImage_leftView
  415. textImage_leftTextfield.isEditable = editable
  416. textImage_leftTextfield.font = font
  417. } else if textImage_type == .Down {
  418. textImageButtonBox.contentView = textImage_downView
  419. textImage_downTextfield.isEditable = editable
  420. textImage_downTextfield.font = font
  421. } else if textImage_type == .Right {
  422. textImageButtonBox.contentView = textImage_rightView
  423. textImage_rightTextfield.isEditable = editable
  424. textImage_rightTextfield.font = font
  425. }
  426. if textImage_state == .Norm {
  427. textImageButtonBox.fillColor = background
  428. textImageButtonBox.borderColor = borderColor
  429. if textImage_type == .Up {
  430. textImage_upImageView.image = image
  431. textImage_upTextfield.textColor = textColor
  432. } else if textImage_type == .Left {
  433. textImage_leftImageView.image = image
  434. textImage_leftTextfield.textColor = textColor
  435. } else if textImage_type == .Down {
  436. textImage_downImageView.image = image
  437. textImage_downTextfield.textColor = textColor
  438. } else if textImage_type == .Right {
  439. textImage_rightImageView.image = image
  440. textImage_rightTextfield.textColor = textColor
  441. }
  442. textImageButtonBox.borderWidth = CGFloat(borderWidth)
  443. textImageButtonBox.cornerRadius = CGFloat(cornerRadius)
  444. paragraphStyle.lineSpacing = lineHeight
  445. } else if state == .Hov {
  446. textImageButtonBox.fillColor = background_hov
  447. textImageButtonBox.borderColor = borderColor_hov
  448. if textImage_type == .Up {
  449. textImage_upImageView.image = image_hov
  450. textImage_upTextfield.textColor = textColor_hov
  451. } else if textImage_type == .Left {
  452. textImage_leftImageView.image = image_hov
  453. textImage_leftTextfield.textColor = textColor_hov
  454. } else if textImage_type == .Down {
  455. textImage_downImageView.image = image_hov
  456. textImage_downTextfield.textColor = textColor_hov
  457. } else if textImage_type == .Right {
  458. textImage_rightImageView.image = image_hov
  459. textImage_rightTextfield.textColor = textColor_hov
  460. }
  461. textImageButtonBox.borderWidth = CGFloat(borderWidth_hov)
  462. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  463. paragraphStyle.lineSpacing = lineHeight_hov
  464. } else if state == .Act {
  465. textImageButtonBox.fillColor = background_act
  466. textImageButtonBox.borderColor = borderColor_act
  467. if textImage_type == .Up {
  468. textImage_upImageView.image = image_act
  469. textImage_upTextfield.textColor = textColor_act
  470. } else if textImage_type == .Left {
  471. textImage_leftImageView.image = image_act
  472. textImage_leftTextfield.textColor = textColor_act
  473. } else if textImage_type == .Down {
  474. textImage_downImageView.image = image_act
  475. textImage_downTextfield.textColor = textColor_act
  476. } else if textImage_type == .Right {
  477. textImage_rightImageView.image = image_act
  478. textImage_rightTextfield.textColor = textColor_act
  479. }
  480. textImageButtonBox.borderWidth = CGFloat(borderWidth_act)
  481. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  482. paragraphStyle.lineSpacing = lineHeight_act
  483. } else if state == .Disabled {
  484. textImageButtonBox.fillColor = background_disabled
  485. textImageButtonBox.borderColor = borderColor_disabled
  486. if textImage_type == .Up {
  487. textImage_upImageView.image = image_disabled
  488. textImage_upTextfield.textColor = textColor_disabled
  489. } else if textImage_type == .Left {
  490. textImage_leftImageView.image = image_disabled
  491. textImage_leftTextfield.textColor = textColor_disabled
  492. } else if textImage_type == .Down {
  493. textImage_downImageView.image = image_disabled
  494. textImage_downTextfield.textColor = textColor_disabled
  495. } else if textImage_type == .Right {
  496. textImage_rightImageView.image = image_disabled
  497. textImage_rightTextfield.textColor = textColor_disabled
  498. }
  499. textImageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  500. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  501. paragraphStyle.lineSpacing = lineHeight_disabled
  502. }
  503. textImage_upImageHeight.constant = CGFloat(textImage_imageHeight)
  504. textImage_upImageWidth.constant = CGFloat(textImage_imageWidth)
  505. textImage_leftImageHeight.constant = CGFloat(textImage_imageHeight)
  506. textImage_leftImageWidth.constant = CGFloat(textImage_imageWidth)
  507. textImage_downImageHeight.constant = CGFloat(textImage_imageHeight)
  508. textImage_downImageWidth.constant = CGFloat(textImage_imageWidth)
  509. textImage_rightImageHeight.constant = CGFloat(textImage_imageHeight)
  510. textImage_rightImageWidth.constant = CGFloat(textImage_imageWidth)
  511. if textImage_type == .Up {
  512. textImage_upTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  513. textImage_upPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  514. textImage_upItem_spacing.constant = CGFloat(textImage_itemSpacing)
  515. } else if textImage_type == .Left {
  516. textImage_leftTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  517. textImage_leftPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  518. textImage_leftItem_spacing.constant = CGFloat(textImage_itemSpacing)
  519. } else if textImage_type == .Down {
  520. textImage_downTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  521. textImage_downPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  522. textImage_downItem_spacing.constant = CGFloat(textImage_itemSpacing)
  523. } else if textImage_type == .Right {
  524. textImage_rightTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  525. textImage_rightPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  526. textImage_rightItem_spacing.constant = CGFloat(textImage_itemSpacing)
  527. }
  528. } else if (buttonType == .RadioButton) || (buttonType == .CheckBox) {
  529. let paragraphStyle = NSMutableParagraphStyle()
  530. if (state == .Norm) {
  531. if (buttonType == .RadioButton) {
  532. radioButton_imageView.image = NSImage(named: "KMRadioButtonUnSelect")
  533. } else {
  534. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_unsel")
  535. }
  536. radioButton_label.font = font
  537. radioButton_label.textColor = textColor
  538. paragraphStyle.lineSpacing = lineHeight
  539. } else if (state == .Hov) {
  540. if (buttonType == .RadioButton) {
  541. radioButton_imageView.image = NSImage(named: "KMRadioButtonHov")
  542. } else {
  543. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_hov")
  544. }
  545. radioButton_label.font = font_hov
  546. radioButton_label.textColor = textColor_hov
  547. paragraphStyle.lineSpacing = lineHeight_hov
  548. } else if (state == .Disabled) {
  549. if (buttonType == .RadioButton) {
  550. radioButton_imageView.image = NSImage(named: "KMRadioButtonUnSel_Disabled")
  551. } else {
  552. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_unsel_Disabled")
  553. }
  554. radioButton_label.font = font_disabled
  555. radioButton_label.textColor = textColor_disabled
  556. paragraphStyle.lineSpacing = lineHeight_disabled
  557. } else if (state == .Checked) {
  558. if (buttonType == .RadioButton) {
  559. radioButton_imageView.image = NSImage(named: "KMRadioButtonSelect")
  560. } else {
  561. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_sel")
  562. }
  563. radioButton_label.font = font_checked
  564. radioButton_label.textColor = textColor_checked
  565. paragraphStyle.lineSpacing = lineHeight_checked
  566. } else if (state == .Checked_dis) {
  567. if (buttonType == .RadioButton) {
  568. radioButton_imageView.image = NSImage(named: "KMRadioButtonSel_Disabled")
  569. } else {
  570. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_sel_Disabled")
  571. }
  572. radioButton_label.font = font_checkeddis
  573. radioButton_label.textColor = textColor_checkeddis
  574. paragraphStyle.lineSpacing = lineHeight_checkeddis
  575. }
  576. radioButton_label.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  577. radio_label_spacing.constant = radio_label
  578. radio_imageViewWidth.constant = radio_imageWidth
  579. radio_imageViewHeight.constant = radio_imageHeight
  580. }
  581. }
  582. }
  583. extension KMDesignButton {
  584. func initDefaultValue() {
  585. if self.buttonType == .Image {
  586. // 边框颜色
  587. self.borderColor = KMAppearance.Interactive.s0Color()
  588. self.borderColor_hov = KMAppearance.Interactive.s0Color()
  589. self.borderColor_act = KMAppearance.Interactive.s0Color()
  590. self.borderColor_disabled = KMAppearance.Interactive.s0Color()
  591. // 边框圆角
  592. self.cornerRadius = 4
  593. self.cornerRadius_hov = 4
  594. self.cornerRadius_act = 4
  595. self.cornerRadius_disabled = 4
  596. // 背景
  597. self.background = KMAppearance.Layout.l1Color()
  598. self.background_hov = KMAppearance.view_bg_dis_color()
  599. self.background_focus = KMAppearance.Layout.l1Color()
  600. // self.background_sel = KMAppearance.buttonSelectedColor()
  601. self.background_act = KMAppearance.buttonSelectedColor()
  602. self.background_disabled = KMAppearance.buttonDisabledColor()
  603. // 字体颜色
  604. // self.textColor = KMAppearance.Layout.h1Color()
  605. // self.textColor_hov = KMAppearance.Layout.h1Color()
  606. // self.textColor_focus = KMAppearance.Layout.h1Color()
  607. // 更新数据
  608. self.updateUI()
  609. }
  610. }
  611. }