// // KMBOTAOutlineCellView.swift // PDF Reader Pro // // Created by lizhe on 2023/4/2. // import Cocoa typealias KMBOTAOutlineCellViewIconAction = (_ view: KMBOTAOutlineCellView ) -> () class KMBOTAOutlineCellView: NSTableCellView { @IBOutlet var contentView: NSView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var iconButton: NSButton! @IBOutlet weak var iconImageWidthConstrailnt: NSLayoutConstraint! var iconAction: KMBOTAOutlineCellViewIconAction? var model: KMBOTAOutlineItem? { didSet { self.reloadData() } } private lazy var hoverBox_: NSBox = { let box = NSBox() box.boxType = .custom box.titlePosition = .noTitle box.contentViewMargins = .zero box.borderWidth = 0 return box }() var hoverBox: NSBox { get { return hoverBox_ } } // MARK: 初始化 override init(frame frameRect: NSRect) { super.init(frame: frameRect) initContentView() setup() } required init?(coder decoder: NSCoder) { super.init(coder: decoder) initContentView() setup() fatalError("init(coder:) has not been implemented") } private func initContentView() { //绑定xib let resource = NSNib(nibNamed: String(describing: self.classForCoder.self), bundle: Bundle(for: self.classForCoder.self))! resource.instantiate(withOwner: self, topLevelObjects: nil) addSubview(contentView) contentView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ contentView.topAnchor.constraint(equalTo: topAnchor), contentView.leftAnchor.constraint(equalTo: leftAnchor), contentView.rightAnchor.constraint(equalTo: rightAnchor), contentView.bottomAnchor.constraint(equalTo: bottomAnchor)]) contentView.updateConstraintsForSubtreeIfNeeded() } func setup() { self.titleLabel.maximumNumberOfLines = 0 contentView.addSubview(hoverBox_) hoverBox_.km_add_leading_constraint(equalTo: iconButton, attribute: .trailing, constant: 4) hoverBox_.km_add_top_constraint() hoverBox_.km_add_bottom_constraint() hoverBox_.km_add_trailing_constraint(constant: -16) } func reloadData() { guard let data = self.model else { return } } func updateUI() { self.titleLabel.textColor = NSColor.km_init(hex: "#252629") self.titleLabel.font = NSFont.SFProTextRegularFont(14.0) } func updateLanguage() { self.reloadData() } @IBAction func iconButtonAction(_ sender: Any) { guard let callBack = iconAction else { return } callBack(self) } }