123456789101112131415161718192021222324252627282930313233343536 |
- //
- // KMButton.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/10/9.
- //
- import Cocoa
- @objcMembers class KMButton: NSButton {
- @objc var mouseMoveCallback: ((Bool) -> Void)?
- override func viewDidMoveToWindow() {
- super.viewDidMoveToWindow()
- if window != nil {
- addTrackingRect(bounds, owner: self, userData: nil, assumeInside: false)
- }
- }
- override func setFrameSize(_ newSize: NSSize) {
- super.setFrameSize(newSize)
- addTrackingRect(NSMakeRect(0, 0, newSize.width, newSize.height), owner: self, userData: nil, assumeInside: false)
- }
- override func mouseEntered(with theEvent: NSEvent) {
- if let callback = mouseMoveCallback {
- callback(true)
- }
- }
- override func mouseExited(with theEvent: NSEvent) {
- if let callback = mouseMoveCallback {
- callback(false)
- }
- }
- }
|