12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // 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 = 8
- self.updateColor(false)
- }
-
- 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)
- }
- }
|