123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // 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(NSMaxX(self.boxView.frame)+vspace, 17, zoomButtonW, zoomButtonW)
- self.zoomInButton.frame = NSMakeRect(NSMaxX(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(NSMaxX(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)
- // }
- }
|