Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
Swift
12345678910111213141516171819202122232425262728293031323334353637import AppKit
/// Tiny NSView subclass whose only job is to surface mouse-enter //// mouse-exit transitions through a closure so the popover can/// reveal hover-only chrome (the floating-piano expand button on/// the visualizer bezel, etc.) without each call site having to/// re-implement a tracking area.final class HoverTrackingView: NSView { var onHoverChanged: ((Bool) -> Void)? private var trackingArea: NSTrackingArea?
override func updateTrackingAreas() { super.updateTrackingAreas() if let trackingArea { removeTrackingArea(trackingArea) } let area = NSTrackingArea( rect: bounds, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil ) addTrackingArea(area) self.trackingArea = area }
override func mouseEntered(with event: NSEvent) { super.mouseEntered(with: event) onHoverChanged?(true) }
override func mouseExited(with event: NSEvent) { super.mouseExited(with: event) onHoverChanged?(false) }}