123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- //
- // KMNTableHeaderCellView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/11/7.
- //
- import Cocoa
- class KMNTableHeaderCellView: NSTableCellView {
- private var contentBox: NSBox = {
- let box = NSBox()
- box.boxType = .custom
- box.titlePosition = .noTitle
- box.contentViewMargins = .zero
- box.borderWidth = 0
- return box
- }()
-
- private var titleLabel_: NSTextField = {
- let view = NSTextField(labelWithString: "")
- return view
- }()
-
- private var leftVLine_: NSView = {
- let view = NSView()
- return view
- }()
-
- private var rightVLine_: NSView = {
- let view = NSView()
- return view
- }()
-
- private var bottomLine_: NSView = {
- let view = NSView()
- return view
- }()
-
- private var button_: NSButton = {
- let view = NSButton()
- view.isBordered = false
- view.title = ""
- return view
- }()
-
- var titleLabel: NSTextField {
- get {
- return self.titleLabel_
- }
- }
-
- var leftLine: NSView {
- get {
- return self.leftVLine_
- }
- }
-
- var rightLine: NSView {
- get {
- return self.rightVLine_
- }
- }
-
- var bottomLine: NSView {
- get {
- return self.bottomLine_
- }
- }
-
- var itemClick: KMCommonClickBlock?
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- convenience init() {
- self.init(frame: .init(x: 0, y: 0, width: 40, height: 40))
-
- initSubviews()
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- initSubviews()
- }
-
- func initSubviews() {
- addSubview(contentBox)
- contentBox.km_add_inset_constraint()
-
- contentBox.contentView?.addSubview(leftVLine_)
- contentBox.contentView?.addSubview(titleLabel_)
- contentBox.contentView?.addSubview(rightVLine_)
- contentBox.contentView?.addSubview(bottomLine_)
-
- leftVLine_.km_add_leading_constraint()
- leftVLine_.km_add_top_constraint(constant: 4)
- leftVLine_.km_add_bottom_constraint(constant: -4)
- leftVLine_.km_add_width_constraint(constant: 0.5)
-
- titleLabel_.km_add_leading_constraint(constant: 8)
- titleLabel_.km_add_centerY_constraint()
-
- rightVLine_.km_add_trailing_constraint()
- rightVLine_.km_add_top_constraint(constant: 4)
- rightVLine_.km_add_bottom_constraint(constant: -4)
- rightVLine_.km_add_width_constraint(constant: 0.5)
-
- bottomLine_.km_add_bottom_constraint(constant: 0)
- bottomLine_.km_add_leading_constraint(constant: 0)
- bottomLine_.km_add_trailing_constraint(constant: 0)
- bottomLine_.km_add_height_constraint(constant: 1)
-
- contentBox.fillColor = .clear
-
- contentBox.addSubview(button_)
- button_.bounds = contentBox.contentView?.bounds ?? .zero
- button_.autoresizingMask = [.width, .height]
- button_.target = self
- button_.action = #selector(_buttonAction)
- }
-
- // MARK: - Private Methods
-
- @objc private func _buttonAction() {
- self.itemClick?(1)
- }
- }
|