KMNSearchReplaceTitleBarView.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // KMNSearchReplaceTitleBarView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/12/3.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNSearchReplaceTitleBarView: NSView {
  10. private lazy var closeButton_: ComponentButton = {
  11. let view = ComponentButton()
  12. let prop = ComponentButtonProperty()
  13. prop.type = .text_gray
  14. prop.size = .xxs
  15. prop.onlyIcon = true
  16. prop.icon = NSImage(named: "KMImageNameSearchReplaceClose")
  17. view.properties = prop
  18. view.setTarget(self, action: #selector(closeAction))
  19. return view
  20. }()
  21. private lazy var switchButton_: ComponentButton = {
  22. let view = ComponentButton()
  23. let prop = ComponentButtonProperty()
  24. prop.type = .text_gray
  25. prop.size = .xxs
  26. prop.onlyIcon = true
  27. prop.icon = NSImage(named: "KMImageNameSearchReplaceSwitch")
  28. view.properties = prop
  29. view.setTarget(self, action: #selector(switchAction))
  30. return view
  31. }()
  32. private lazy var titleLabel_: NSTextField = {
  33. let view = NSTextField(labelWithString: "")
  34. return view
  35. }()
  36. var titleLabel: NSTextField {
  37. get {
  38. return titleLabel_
  39. }
  40. }
  41. var itemClick: KMCommonClickBlock?
  42. convenience init() {
  43. self.init(frame: .init(x: 0, y: 0, width: 300, height: 44))
  44. }
  45. override func awakeFromNib() {
  46. super.awakeFromNib()
  47. initSubviews()
  48. }
  49. override init(frame frameRect: NSRect) {
  50. super.init(frame: frameRect)
  51. initSubviews()
  52. }
  53. required init?(coder: NSCoder) {
  54. super.init(coder: coder)
  55. initSubviews()
  56. }
  57. func initSubviews() {
  58. addSubview(closeButton_)
  59. addSubview(switchButton_)
  60. addSubview(titleLabel_)
  61. closeButton_.km_add_size_constraint(size: .init(width: 24, height: 24))
  62. closeButton_.km_add_top_constraint(constant: 8)
  63. closeButton_.km_add_trailing_constraint(constant: -8)
  64. switchButton_.km_add_size_constraint(size: .init(width: 24, height: 24))
  65. switchButton_.km_add_top_constraint(constant: 8)
  66. switchButton_.km_add_trailing_constraint(equalTo: closeButton_, attribute: .leading, constant: -8)
  67. titleLabel_.km_add_leading_constraint(constant: 24)
  68. titleLabel_.km_add_top_constraint(constant: 24)
  69. }
  70. @objc func closeAction() {
  71. itemClick?(1)
  72. }
  73. @objc func switchAction() {
  74. itemClick?(2)
  75. }
  76. }