12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // KMBotaTableRowView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/28.
- //
- import Cocoa
- import KMComponentLibrary
- typealias KMAnnOutlineRowViewRightMouseCallback = (_ view: KMBotaTableRowView, _ event: NSEvent) -> Void
- class KMBotaTableRowView: NSTableRowView {
- var selectCallback: ((KMBotaTableRowView)->Void)?
- var rightMouseCallback: KMAnnOutlineRowViewRightMouseCallback?
-
- var contentBox: KMBox?
- convenience init() {
- self.init(frame: .zero)
-
- self.addTrackingArea()
- }
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- addBox()
- // Drawing code here.
- }
-
- func addTrackingArea() {
- let trackingArea = NSTrackingArea(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self, userInfo: nil)
- self.addTrackingArea(trackingArea)
- }
-
- func addBox() {
- if self.contentBox == nil {
- let rect = self.bounds
- self.contentBox?.wantsLayer = true
- self.contentBox = KMBox(frame: rect)
- self.contentBox?.borderWidth = 0
- self.contentBox?.boxType = .custom
- self.contentBox?.autoresizingMask = [.width, .height]
- self.contentBox?.rightDownCallback = { [unowned self] (downEntered, mouseBox, event) in
- guard let callBack = rightMouseCallback else { return }
-
- callBack(self, event)
- }
- }
- self.addSubview(contentBox!)
- }
-
- override func drawSelection(in dirtyRect: NSRect) {
- let selectionRect = self.bounds
- let color = ComponentLibrary.shared.getComponentColorFromKey("colorPrimary/bg-opacity-dark")
- color.setFill()
- let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 0, yRadius: 0)
- selectionRect.fill()
- }
-
- override var isSelected: Bool {
- get {
- return super.isSelected
- }
- set {
- super.isSelected = newValue
-
- self.selectCallback?(self)
- }
- }
- }
|