KMComparativeTableView.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // KMComparativeTableView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/24.
  6. //
  7. import Cocoa
  8. typealias KMComparativeTableViewCloseAction = (_ view: KMComparativeTableView) -> Void
  9. typealias KMComparativeTableViewLoginAction = (_ view: KMComparativeTableView) -> Void
  10. typealias KMComparativeTableViewSignUpAction = (_ view: KMComparativeTableView) -> Void
  11. class KMComparativeTableView: KMBaseXibView {
  12. @IBOutlet weak var closeBox: KMBox!
  13. @IBOutlet weak var closeButton: NSButton!
  14. @IBOutlet weak var signUpButton: NSButton!
  15. @IBOutlet weak var loginButton: NSButton!
  16. @IBOutlet weak var outlineView: KMComparativeOutlineView!
  17. var closeAction: KMComparativeTableViewCloseAction?
  18. var loginAction: KMComparativeTableViewLoginAction?
  19. var signUpAction: KMComparativeTableViewSignUpAction?
  20. override func draw(_ dirtyRect: NSRect) {
  21. super.draw(dirtyRect)
  22. // Drawing code here.
  23. }
  24. override func setup() {
  25. super.setup()
  26. self.closeBox.moveCallback = { [weak self] (mouseEntered, mouseBox) in
  27. if mouseEntered {
  28. self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
  29. } else {
  30. self?.closeButton.image = NSImage(named: "control_btn_icon_close")
  31. }
  32. }
  33. }
  34. override func updateUI() {
  35. super.updateUI()
  36. self.backgroundColor(NSColor(hex: "#F2F9FF"))
  37. self.loginButton.backgroundColor(NSColor(hex: "#1770F4"))
  38. self.loginButton.border(NSColor(hex: "#1770F4"), 1, 4)
  39. self.loginButton.contentTintColor = NSColor(hex: "FFFFFF")
  40. self.signUpButton.contentTintColor = NSColor(hex: "#1770F4")
  41. }
  42. override func reloadData() {
  43. super.reloadData()
  44. }
  45. override func updateLanguage() {
  46. super.updateLanguage()
  47. self.signUpButton.title = NSLocalizedString("Sign Up", comment: "")
  48. self.loginButton.title = NSLocalizedString("Log In", comment: "")
  49. }
  50. }
  51. protocol KMComparativeTableViewAction {}
  52. extension KMComparativeTableView: KMComparativeTableViewAction {
  53. @IBAction func closeButtonAction(_ sender: Any) {
  54. guard let callBack = closeAction else { return }
  55. callBack(self)
  56. }
  57. @IBAction func signUpButtonAction(_ sender: Any) {
  58. guard let callBack = signUpAction else { return }
  59. callBack(self)
  60. }
  61. @IBAction func loginButtonAction(_ sender: Any) {
  62. guard let callBack = loginAction else { return }
  63. callBack(self)
  64. }
  65. }