// // KMNBotaAnnotationHeaderView.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/12/6. // import Cocoa import KMComponentLibrary class KMNSectionHeaderView: NSView { private lazy var contentBox_: NSBox = { let view = NSBox() view.boxType = .custom view.titlePosition = .noTitle view.contentViewMargins = .zero view.borderWidth = 0 return view }() private lazy var expandButton_: NSButton = { let view = NSButton() view.isBordered = false view.imagePosition = .imageOnly return view }() private lazy var titleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") return view }() private lazy var numLabel_: NSTextField = { let view = NSTextField(labelWithString: "") return view }() private var leftConst_: NSLayoutConstraint? private var topConst_: NSLayoutConstraint? private var rightConst_: NSLayoutConstraint? private var bottomConst_: NSLayoutConstraint? var expandButton: NSButton { get { return expandButton_ } } var titleLabel: NSTextField { get { return titleLabel_ } } var numLabel: NSTextField { get { return numLabel_ } } var contentInset: NSEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: 0) { didSet { leftConst_?.constant = contentInset.left topConst_?.constant = contentInset.top rightConst_?.constant = -contentInset.right bottomConst_?.constant = -contentInset.bottom } } var itemClick: KMCommonClickBlock? convenience init() { self.init(frame: .init(x: 0, y: 0, width: 10, height: 10)) } override init(frame frameRect: NSRect) { super.init(frame: frameRect) initSubviews() } required init?(coder: NSCoder) { super.init(coder: coder) initSubviews() } override func awakeFromNib() { super.awakeFromNib() initSubviews() } func initSubviews() { addSubview(contentBox_) leftConst_ = contentBox_.km_add_leading_constraint_r() rightConst_ = contentBox_.km_add_trailing_constraint_r() topConst_ = contentBox_.km_add_top_constraint_r() bottomConst_ = contentBox_.km_add_bottom_constraint_r() let wh: CGFloat = 16 let vspace: CGFloat = 8 contentBox_.contentView?.addSubview(expandButton) expandButton.km_add_leading_constraint() expandButton.km_add_size_constraint(size: .init(width: wh, height: wh)) expandButton.km_add_centerY_constraint() contentBox_.contentView?.addSubview(titleLabel) titleLabel.km_add_centerY_constraint() titleLabel.km_add_leading_constraint(equalTo: expandButton, attribute: .trailing, constant: 2 * vspace) contentBox_.contentView?.addSubview(numLabel_) numLabel_.km_add_centerY_constraint() numLabel_.km_add_trailing_constraint(constant: -vspace) } } class KMNBotaAnnotationHeaderView: NSView { private lazy var titleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") view.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold") view.textColor = KMNColorTools.colorText_2() return view }() private lazy var searchButton_: ComponentButton = { let view = ComponentButton() let prop = ComponentButtonProperty() prop.type = .text_gray prop.size = .xxs prop.onlyIcon = true prop.icon = NSImage(named: "KMImageNameOutlineSearch") view.properties = prop return view }() private lazy var sortButton_: ComponentButton = { let view = ComponentButton() let prop = ComponentButtonProperty() prop.type = .text_gray prop.size = .xxs prop.onlyIcon = true prop.icon = NSImage(named: "KMImageNameBotaSearch") view.properties = prop return view }() private lazy var moreButton_: ComponentButton = { let view = ComponentButton() let prop = ComponentButtonProperty() prop.type = .text_gray prop.size = .xxs prop.onlyIcon = true prop.icon = NSImage(named: "KMImageNameOutlineMore") view.properties = prop return view }() private lazy var bottomLine_: NSView = { let view = NSView() view.wantsLayer = true return view }() var titleLabel: NSTextField { get { return titleLabel_ } } var searchButton: ComponentButton { get { return searchButton_ } } var sortButton: ComponentButton { get { return sortButton_ } } var moreButton: ComponentButton { get { return moreButton_ } } var bottomLine: NSView { get { return bottomLine_ } } var itemClick: KMCommonClickBlock? convenience init() { self.init(frame: .init(x: 0, y: 0, width: 300, height: 40)) initSubviews() } override func awakeFromNib() { super.awakeFromNib() initSubviews() } func initSubviews() { let margin: CGFloat = 12 addSubview(titleLabel_) titleLabel_.km_add_leading_constraint(constant: margin) titleLabel_.km_add_centerY_constraint() let vspace: CGFloat = 8 let wh: CGFloat = 24 addSubview(moreButton_) moreButton_.km_add_size_constraint(size: .init(width: wh, height: wh)) moreButton_.km_add_trailing_constraint(constant: -margin) moreButton_.km_add_centerY_constraint() moreButton_.setTarget(self, action: #selector(moreAction)) addSubview(sortButton_) sortButton_.km_add_size_constraint(size: .init(width: wh, height: wh)) sortButton_.km_add_trailing_constraint(equalTo: moreButton_, attribute: .leading, constant: -vspace) sortButton_.km_add_centerY_constraint() sortButton_.setTarget(self, action: #selector(sortAction)) addSubview(searchButton_) searchButton_.km_add_size_constraint(size: .init(width: wh, height: wh)) searchButton_.km_add_trailing_constraint(equalTo: sortButton_, attribute: .leading, constant: -vspace) searchButton_.km_add_centerY_constraint() searchButton_.setTarget(self, action: #selector(searchAction)) addSubview(bottomLine_) bottomLine_.km_add_leading_constraint() bottomLine_.km_add_trailing_constraint() bottomLine_.km_add_bottom_constraint() bottomLine_.km_add_height_constraint(constant: 1) } @objc func searchAction() { itemClick?(1) } @objc func sortAction() { itemClick?(2) } @objc func moreAction() { itemClick?(3) } }