KMPDFMergeFileNameTabelViewCell.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // KMPDFMergeFileNameTabelViewCell.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/10/11.
  6. //
  7. import Cocoa
  8. @objcMembers class KMPDFMergeFileNameTabelViewCell: NSTableCellView {
  9. var numberLabel: NSTextField?
  10. var iconImageView: NSImageView?
  11. var fileNameLabel: NSTextField?
  12. var pageNumberLabel: NSTextField?
  13. override init(frame frameRect: NSRect) {
  14. super.init(frame: frameRect)
  15. self.initSubviews()
  16. }
  17. required init?(coder: NSCoder) {
  18. super.init(coder: coder)
  19. self.initSubviews()
  20. }
  21. override var isFlipped: Bool {
  22. return true
  23. }
  24. func initSubviews() {
  25. let numberLabel = NSTextField(labelWithString: "")
  26. numberLabel.textColor = NSColor(red: 37.0/255.0, green: 38.0/255.0, blue: 41.0/255.0, alpha: 1.0)
  27. numberLabel.font = .SFProTextRegularFont(14)
  28. numberLabel.alignment = .center
  29. numberLabel.lineBreakMode = .byTruncatingTail
  30. self.addSubview(numberLabel)
  31. self.numberLabel = numberLabel
  32. let iconImageView = NSImageView()
  33. self.addSubview(iconImageView)
  34. self.iconImageView = iconImageView
  35. let fileNameLabel = NSTextField(labelWithString: "")
  36. fileNameLabel.textColor = NSColor(red: 37.0/255.0, green: 38.0/255.0, blue: 41.0/255.0, alpha: 1.0)
  37. fileNameLabel.font = .SFProTextRegularFont(14)
  38. fileNameLabel.lineBreakMode = .byTruncatingTail
  39. self.addSubview(fileNameLabel)
  40. self.fileNameLabel = fileNameLabel
  41. let pageNumberLabel = NSTextField(labelWithString: "")
  42. pageNumberLabel.textColor = NSColor(red: 148.0/255.0, green: 152.0/255.0, blue: 156.0/255.0, alpha: 1.0)
  43. pageNumberLabel.font = .SFProTextRegularFont(14)
  44. self.addSubview(pageNumberLabel)
  45. self.pageNumberLabel = pageNumberLabel
  46. }
  47. override func layout() {
  48. super.layout()
  49. let width = NSWidth(self.bounds)
  50. let height = NSHeight(self.bounds)
  51. let labelH = 22.0
  52. self.numberLabel?.frame = NSMakeRect(16, (height-labelH)*0.5, 30+16, labelH)
  53. let iconSize = 60.0
  54. self.iconImageView?.frame = NSMakeRect(NSMaxX(self.numberLabel?.frame ?? NSZeroRect)+6, (height-iconSize)*0.5, iconSize, iconSize)
  55. let fileNameX = NSMaxX(self.iconImageView?.frame ?? NSZeroRect)+8
  56. self.fileNameLabel?.frame = NSMakeRect(fileNameX, 13, width-fileNameX, labelH)
  57. self.pageNumberLabel?.frame = NSMakeRect(fileNameX, NSMaxY(self.fileNameLabel?.frame ?? NSZeroRect)+8, width-fileNameX, labelH)
  58. }
  59. }