// // 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? 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(5, with: 44) // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarThumbnailNor)!, for: 0) // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarOutlineNor)!, for: 1) // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarAnnotationNor)!, for: 2) // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSnapshotNor)!, for: 3) // self.segmentedControl.setImage(NSImage(named: KMImageNameUXIconSidetabbarSearchNor)!, for: 4) // self.segmentedControl.setToolTip(KMLocalizedString("View Thumbnails"), for: 0) // self.segmentedControl.setToolTip(KMLocalizedString("View Outline"), for: 1) // self.segmentedControl.setToolTip(KMLocalizedString("View Notes"), for: 2) // self.segmentedControl.setToolTip(KMLocalizedString("View Snapshots"), for: 3) // self.segmentedControl.setToolTip(KMLocalizedString("Search"), for: 4) 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(NSLocalizedString("Search", comment: ""), for: 0) self.segmentedControl.setToolTip(NSLocalizedString("View Thumbnails", comment: ""), for: 1) self.segmentedControl.setToolTip(NSLocalizedString("View Outline", comment: ""), for: 2) self.segmentedControl.setToolTip(NSLocalizedString("View Notes", comment: ""), for: 3) self.segmentedControl.setToolTip(NSLocalizedString("View Bookmarks", comment: ""), for: 4) self.segmentedControl.setToolTip(NSLocalizedString("View Snapshots", comment: ""), 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) } }