3

I’m having some difficulty getting an NSTextView embedded in an NSScrollView with a horizontal NSRulerView to play well with a rounded corner mask. I’ve created a simple test application to localize the issue.

First, it appears there are basically two ways to get rounded corners on an NSScrollView. The first is to use a CAShapeLayer and set it’s path property to the desired rounded rectangle bezier path. The second is to set a CALayer’s cornerRadius property to the desired value, and then set it’s backgroundColor property to any color with a 1.0 alpha (such as solid black). Either of these layers can then be used to set the NSScrollView’s backing layer’s mask property, after making it layer-backed via setWantsLayer:. Though I get some drawing artifacts when I apply it directly to the NSScrollView's backing layer. So instead, I apply the mask to the NSScrollView’s superview's backing layer. The superview itself is just a simple container view.

Now, the problem arises when we show the ruler view and begin interacting with it. The ruler view itself looks great, it has rounded corners because of the mask applied above. However, when I start to add and drag markers, they are invisible until I release the mouse, making it very difficult to position markers. Also, the standard vertical marker lines do not appear while dragging.

I’ve confirmed that this is occurring due to the presence of the mask. When I disable the mask, the NSRulerView behaves normally.

So the question is, how can I get NSRulerView and NSScrollView’s rounded corners to play well together?

It looks almost as if the mask layer is somehow obscuring the temporary drawing that’s occurring in the NSRulerView during mouse-drag tracking. If this is the case, how do I get the NSRulerView to perform it’s drawing above everything else? Making it and all other views layer-backed, as well as positioning the NSRulerView above all sibling views (for good measure) doesn’t seem to have any effect.

I’ve also tried subclassing NSTextView to override the delegate method rulerView:willMoveMarker: (and others) to force drawing, but it seems to draw the marker in a weird location, near the bottom left of the window, nowhere near the NSRulerView, even after ensuring I’m in the right coordinate system. I suspect this is a drawing artifact, though, since forcing it to draw elsewhere has no effect.

Dalmazio
  • 1,835
  • 2
  • 23
  • 40

0 Answers0