123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // KMTableRowView.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2023/10/10.
- //
- import Cocoa
- class KMTableRowView: NSTableRowView {
-
- var _hasBottomLine: Bool = false
- var _bottomLineColor: NSColor?
- var selectionInset: NSEdgeInsets = NSEdgeInsets()
- @objc var selectionRadius: CGFloat = 0.0
- @objc var selectionBackgroundColorBlock: (() -> NSColor)?
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- addTrackingArea()
- selectionInset = NSEdgeInsetsZero
- selectionRadius = 0.0
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
-
- var hasBottomLine: Bool {
- get {
- return _hasBottomLine
- }
- set {
- _hasBottomLine = newValue
- self.needsDisplay = true
- }
- }
-
- var bottomLineColor: NSColor? {
- get {
- return _bottomLineColor
- }
- set {
- _bottomLineColor = newValue
- self.needsDisplay = true
- }
- }
-
- //MARK: Private Methods
-
- func addTrackingArea() {
- let trackingArea = NSTrackingArea.init(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self)
- self.addTrackingArea(trackingArea)
- }
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- if self.hasBottomLine {
- var color = self.bottomLineColor
- if color == nil {
- color = NSColor.lightGray
- }
- color!.setStroke()
- color!.setFill()
-
- let lineRect = NSRect(x: 0, y: NSHeight(bounds) - 1, width: NSWidth(bounds), height: 1)
- let linePath = NSBezierPath(roundedRect: lineRect, xRadius: 0, yRadius: 0)
- linePath.fill()
- linePath.stroke()
- }
- }
- override func drawSelection(in dirtyRect: NSRect) {
- if selectionBackgroundColorBlock == nil {
- let selectionRect = NSRect(x: selectionInset.left, y: selectionInset.top, width: NSWidth(bounds) - selectionInset.left - selectionInset.right, height: NSHeight(bounds) - selectionInset.top - selectionInset.bottom)
- // NSColor.lightGray.setFill()
- KMAppearance.Status.selColor().setFill()
- let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: selectionRadius, yRadius: selectionRadius)
- selectionPath.fill()
- return
- }
- let selectionRect = NSRect(x: selectionInset.left, y: selectionInset.top, width: NSWidth(bounds) - selectionInset.left - selectionInset.right, height: NSHeight(bounds) - selectionInset.top - selectionInset.bottom)
- let color = selectionBackgroundColorBlock!()
- color.setStroke()
- color.setFill()
- let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: selectionRadius, yRadius: selectionRadius)
- selectionPath.fill()
- selectionPath.stroke()
- }
- override func mouseEntered(with event: NSEvent) {
- super.mouseEntered(with: event)
- }
- }
|