// // KMToolbarZoomItemView.swift // PDF Reader Pro // // Created by tangchao on 2023/11/28. // import Cocoa class KMToolbarZoomItemView: NSView { lazy var boxView: NSView = { let view = NSView() view.frame = NSMakeRect(0, 16, 70, 22) return view }() weak var zoomView: NSView? lazy var titleLabel: NSTextField = { let label = NSTextField(labelWithString: NSLocalizedString("Zoom", comment: "")) label.frame = NSMakeRect(0, 0, 70, 14) label.alignment = .right label.font = KMToolbarMainItemView.textFont label.textColor = KMAppearance.subtitleColor() return label }() lazy var zoomInButton: NSButton = { let button = KMCoverButton() button.wantsLayer = true button.layer?.cornerRadius = 4 button.isBordered = false button.title = "" button.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor") button.target = self button.action = #selector(_buttonClicked) button.coverAction = { cbtn, caction in if caction == .enter { cbtn.layer?.backgroundColor = KMToolbarItemView.selectedBackgroundColor.cgColor } else if caction == .exit { cbtn.layer?.backgroundColor = KMToolbarItemView.normalBackgroundColor.cgColor } } return button }() lazy var zoomOutButton: NSButton = { let button = KMCoverButton() button.isBordered = false button.wantsLayer = true button.layer?.cornerRadius = 4 button.title = "" button.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor") button.target = self button.action = #selector(_buttonClicked) button.coverAction = { cbtn, caction in if caction == .enter { cbtn.layer?.backgroundColor = KMToolbarItemView.selectedBackgroundColor.cgColor } else if caction == .exit { cbtn.layer?.backgroundColor = KMToolbarItemView.normalBackgroundColor.cgColor } } return button }() var callback: KMCommonClickBlock? convenience init(zoomView: NSView?) { let vspace: CGFloat = 2 let zoomButtonW: CGFloat = 20 self.init(frame: NSMakeRect(0, 0, 70+2*zoomButtonW+vspace, 40)) self.zoomView = zoomView self.addSubview(self.boxView) if let zview = self.zoomView { self.boxView.addSubview(zview) self.zoomView?.frame = NSMakeRect(10, 3, NSWidth(zview.frame), NSHeight(zview.frame)) } self.addSubview(self.titleLabel) self.addSubview(self.zoomInButton) self.addSubview(self.zoomOutButton) self.zoomOutButton.frame = NSMakeRect(CGRectGetMaxX(self.boxView.frame)+vspace, 17, zoomButtonW, zoomButtonW) self.zoomInButton.frame = NSMakeRect(CGRectGetMaxX(self.zoomOutButton.frame), 17, zoomButtonW, zoomButtonW) self.boxView.wantsLayer = true self.boxView.layer?.borderWidth = 1 self.boxView.layer?.borderColor = NSColor.lightGray.cgColor } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) } } // MARK: - Private Methods extension KMToolbarZoomItemView { @objc private func _buttonClicked(_ sender: NSButton) { var idx = 1 if self.zoomInButton.isEqual(to: sender) { idx = 2 } guard let block = self.callback else { return } block(idx) } } class KMToolbarPageIndicatorItemView: NSView { lazy var boxView: NSView = { let view = NSView() view.frame = NSMakeRect(0, 16, 50, 22) return view }() weak var zoomView: NSView? lazy var titleLabel: NSTextField = { let label = NSTextField(labelWithString: NSLocalizedString("Page", comment: "")) label.frame = NSMakeRect(0, 0, 50, 14) label.alignment = .right label.font = KMToolbarMainItemView.textFont label.textColor = KMAppearance.subtitleColor() return label }() lazy var numLabel: NSTextField = { let label = NSTextField(labelWithString: NSLocalizedString("/ 29", comment: "")) label.frame = NSMakeRect(0, 0, 40, 14) label.alignment = .right label.font = KMToolbarMainItemView.textFont label.textColor = KMAppearance.subtitleColor() return label }() var callback: KMCommonClickBlock? convenience init(zoomView: NSView?) { let vspace: CGFloat = 2 let zoomButtonW: CGFloat = 40 self.init(frame: NSMakeRect(0, 0, 50+zoomButtonW+vspace, 40)) self.zoomView = zoomView self.addSubview(self.boxView) if let zview = self.zoomView { self.boxView.addSubview(zview) self.zoomView?.frame = NSMakeRect(10, 3, NSWidth(zview.frame), NSHeight(zview.frame)) } self.addSubview(self.titleLabel) self.addSubview(self.numLabel) self.numLabel.frame = NSMakeRect(CGRectGetMaxX(self.boxView.frame)+vspace, 13, zoomButtonW, 20) self.boxView.wantsLayer = true self.boxView.layer?.borderWidth = 1 self.boxView.layer?.borderColor = NSColor.lightGray.cgColor } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) } } // MARK: - Private Methods extension KMToolbarPageIndicatorItemView { // @objc private func _buttonClicked(_ sender: NSButton) { // var idx = 1 // if self.zoomInButton.isEqual(to: sender) { // idx = 2 // } // // guard let block = self.callback else { // return // } // block(idx) // } }