I'm creating a view that has rounded corners and I want the view to highlight when the mouse hovers over it. The problem is that the NSTrackingArea
registers a mouseEntered:
event when the mouse is outside of the corners. Is there a way to override how it determines if it's in the view?
I've tried:
- Adding
.inVisibleRect
to theNSTrackingArea.Options
- Overriding
isMousePoint:in:
If necessary, I can implement mouseEntered:
to ignore all events whose points aren't within the rectangle, but I was wondering if there was a more elegant way (i.e where mouseEntered:
gets called only when the mouse actually enters the view).
This is the code I use for drawing (it works for me):
...
override func draw(_ dirtyRect: NSRect)
{
let path = NSBezierPath(roundedRect: dirtyRect, xRadius: radius, yRadius: radius)
path.addClip()
backgroundColor.setFill()
dirtyRect.fill()
}
...
override func mouseEntered(with event: NSEvent)
{
print("Mouse entered!")
}
Let me know if I can clarify anything. Thanks for the help!
dirtyRect
is "A rectangle defining the portion of the view that requires redrawing.". – Willeke