KMDesignButton.swift 27 KB

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