// // KMNSearchReplaceTitleBarView.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/12/3. // import Cocoa import KMComponentLibrary class KMNSearchReplaceTitleBarView: NSView { private lazy var closeButton_: ComponentButton = { let view = ComponentButton() let prop = ComponentButtonProperty() prop.type = .text_gray prop.size = .xxs prop.onlyIcon = true prop.icon = NSImage(named: "KMImageNameSearchReplaceClose") view.properties = prop view.setTarget(self, action: #selector(closeAction)) return view }() private lazy var switchButton_: ComponentButton = { let view = ComponentButton() let prop = ComponentButtonProperty() prop.type = .text_gray prop.size = .xxs prop.onlyIcon = true prop.icon = NSImage(named: "KMImageNameSearchReplaceSwitch") view.properties = prop view.setTarget(self, action: #selector(switchAction)) return view }() private lazy var titleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") return view }() var titleLabel: NSTextField { get { return titleLabel_ } } var itemClick: KMCommonClickBlock? convenience init() { self.init(frame: .init(x: 0, y: 0, width: 300, height: 44)) } override func awakeFromNib() { super.awakeFromNib() initSubviews() } override init(frame frameRect: NSRect) { super.init(frame: frameRect) initSubviews() } required init?(coder: NSCoder) { super.init(coder: coder) initSubviews() } func initSubviews() { addSubview(closeButton_) addSubview(switchButton_) addSubview(titleLabel_) closeButton_.km_add_size_constraint(size: .init(width: 24, height: 24)) closeButton_.km_add_top_constraint(constant: 8) closeButton_.km_add_trailing_constraint(constant: -8) switchButton_.km_add_size_constraint(size: .init(width: 24, height: 24)) switchButton_.km_add_top_constraint(constant: 8) switchButton_.km_add_trailing_constraint(equalTo: closeButton_, attribute: .leading, constant: -8) titleLabel_.km_add_leading_constraint(constant: 24) titleLabel_.km_add_top_constraint(constant: 24) } @objc func closeAction() { itemClick?(1) } @objc func switchAction() { itemClick?(2) } }