123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // KMBotaLeftView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/22.
- //
- import Cocoa
- class KMBotaLeftView: NSView {
- var segmentedControl: KMSegmentedControl = {
- let view = KMSegmentedControl()
- return view
- }()
-
- var helpButton: KMCoverButton = {
- let view = KMCoverButton()
- view.title = ""
- view.image = NSImage(named: "KMImgNameUserFbHelpIcon")
- view.isBordered = false
- return view
- }()
-
- var ttsButton: NSButton = {
- let view = NSButton()
- view.title = ""
- view.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTTS)
- view.isBordered = false
- view.imageScaling = NSImageScaling.scaleAxesIndependently
- return view
- }()
-
- var itemClick: KMItemClickBlock<KMBotaLeftView>?
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- self.initSubview()
- self.initDefaultValue()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- self.initSubview()
- self.initDefaultValue()
- }
-
- func initSubview() {
- self.addSubview(self.segmentedControl)
- self.addSubview(self.helpButton)
- self.addSubview(self.ttsButton)
- self.ttsButton.target = self
- self.ttsButton.action = #selector(ttsAction)
- }
-
- func initDefaultValue() {
- self.segmentedControl.direction = .vertical
- self.segmentedControl.setSegmentCount(6, with: 44)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 0)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 1)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 2)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 3)
- self.segmentedControl.setImage(NSImage(named: "KMImageNameSidebarBookMarkNor")!, for: 4)
- self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 5)
-
- self.segmentedControl.setToolTip(KMLocalizedString("Search", nil), for: 0)
- self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails", nil), for: 1)
- self.segmentedControl.setToolTip(KMLocalizedString("View Outline", nil), for: 2)
- self.segmentedControl.setToolTip(KMLocalizedString("View Notes", nil), for: 3)
- self.segmentedControl.setToolTip(KMLocalizedString("View Bookmarks", nil), for: 4)
- self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots", nil), for: 5)
-
- self.segmentedControl.selectedSegment = UInt8.max
- self.segmentedControl.wantsLayer = true
- self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- }
-
- override func layout() {
- super.layout()
-
- self.segmentedControl.frame = self.bounds
- self.helpButton.frame = NSMakeRect(4, 0, 36, 36)
- self.ttsButton.frame = NSMakeRect(14, NSMaxY(self.helpButton.frame)+6, 16, 16)
- }
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- }
-
- override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- super.interfaceThemeDidChanged(appearance)
-
- self.segmentedControl.appearance = .init(named: appearance)
- self.segmentedControl.wantsLayer = true
- // self.segmentedControl.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
- if KMAppearance.isDarkMode() {
- self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
- } else {
- self.segmentedControl.layer?.backgroundColor = NSColor.km_init(hex: "#EBECF0", alpha: 1).cgColor
- }
- }
-
- @objc func ttsAction() {
- self.itemClick?(self, 1)
- }
- }
|