123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // KMAdvertisementCollectionViewItem.swift
- // KMAdvertisement
- //
- // Created by lizhe on 2022/11/28.
- //
- import Cocoa
- class KMAdvertisementCollectionViewItem: NSCollectionViewItem {
- @IBOutlet weak var iconImageView: NSImageView!
- @IBOutlet weak var titleLabel: NSTextField!
-
- @IBOutlet weak var contentView: NSView!
- var model: KMAdvertisementItemInfo? {
- didSet {
- self.reloadData()
- }
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
- self.view.addTrackingRect(self.view.bounds, owner: self, userData: nil, assumeInside: false)
- self.contentView.wantsLayer = true
- self.contentView.layer?.masksToBounds = true
- self.updateColor(false)
- // self.contentView.layer?.backgroundColor = NSColor.init(red: 38.0/255.0, green: 40/255.0, blue: 43/255.0, alpha: 1).cgColor
- }
-
- func reloadData() {
- self.titleLabel.stringValue = KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.name)
- // self.titleLabel.font = NSFont.init(name: model?.title?.font?.name ?? "AppleSystemUIFont", size: CGFloat(model?.title?.font?.size ?? 13))
- self.contentView.toolTip = KMAdvertisementModelTransition.transitionLanguage(langeuage: model?.tooltip)
- self.contentView.layer?.cornerRadius = 4
- self.updateColor(false)
- }
-
- func updateColor(_ highlight: Bool) {
- // self.view.appearance = NSAppearance(named: .aqua)
- if highlight {
- if KMAdvertisementConfig.isDarkModel() {
- self.titleLabel.textColor = NSColor.km_init(hex: "#4E7EDB")
- self.contentView.backgroundColor(NSColor.km_init(hex: "#FFFFFF", alpha: 0.05))
- } else {
- self.titleLabel.textColor = NSColor.km_init(hex: "#273C62")
- self.contentView.backgroundColor(NSColor.km_init(hex: "#000000", alpha: 0.05))
- }
- } else {
- if KMAdvertisementConfig.isDarkModel() {
- self.contentView.backgroundColor(NSColor.km_init(hex: "#26282B"))
- self.titleLabel.textColor = NSColor.km_init(hex: "#C8C9CC")
- } else {
- self.contentView.backgroundColor(NSColor.km_init(hex: "#FCFDFF"))
- self.titleLabel.textColor = NSColor.km_init(hex: "#42464D")
- }
- }
-
- let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model?.image, highlight: highlight))
- self.iconImageView.image = KMAdvertisementImage.imageWithURL(url: url, completion: { [weak self] image in
- self?.iconImageView.image = image
- })
- }
-
- // func updateColor(_ highlight: Bool) {
- //
- // if highlight {
- // self.titleLabel.textColor = KMAppearance.Layout.mColor()
- // self.contentView.layer?.backgroundColor = KMAppearance.Status.hovColor().cgColor
- // } else {
- // self.titleLabel.textColor = KMAppearance.Layout.h1Color()
- // self.contentView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
- // }
- //
- // let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model?.image, highlight: highlight))
- // self.iconImageView.image = KMAdvertisementImage.imageWithURL(url: url, completion: { [weak self] image in
- // self?.iconImageView.image = image
- // })
- // }
-
- override func mouseEntered(with event: NSEvent) {
- self.updateColor(true)
- }
- override func mouseExited(with event: NSEvent) {
- self.updateColor(false)
- }
- }
|