Zooming Breaks Focus-ring Architecture (10.13.1)
Zooming Breaks Focus-ring Architecture (10.13.1)
- Subject: Zooming Breaks Focus-ring Architecture (10.13.1)
- From: Joel Norvell <email@hidden>
- Date: Mon, 04 Dec 2017 19:58:47 -0800
Dear Cocoa-dev People,
The main view of my app can be zoomed by the user. It contains
NSTextView subviews. The NSTextView focus-rings are well-drawn when the
main view is not zoomed. But when it is zoomed, focus rings are not
drawn properly. They are drawn the same size, no matter what the zoom
factor. And they drift downward as zoom is increased. Note that the text
fields themselves are zoomed properly and all mouse clicks are
interpreted correctly in zoomed views; just the focus-rings are wrong.
Am I doing something wrong? Is there any way to get zoomed focus rings
to work using the Cocoa focus ring APIs?
Thanks,
Joel Norvell
This describes my zoom-architecture:
// "self" is an NSImageView subclass containing NSTextViews as subviews.
- (void) doZoom:(float)scale
{
float width = [[self bounds].width;
float height = [[self bounds].height;
NSRect zoomedRect = NSMakeRect(0, 0, width*scale,
height*scale*pages);
NSRect boundsRect = NSMakeRect(0, 0, width, height*pages);
// Make view corners have integral values.
zoomedRect = [self roundedRect:zoomedRect];
[self setFrame:zoomedRect];
[self setBounds:boundsRect];
[self setNeedsDisplay:YES];
[self scrollToTop];
}
// "self" is an NSTextField nested in the NSImageView subclass.
// Part of initialization pertinent to focus-rings
// N.B. My NSTextField subclass doesn't use or explicitly do anything to
opt-into Core Animation layers.
- (void) initTextField;
{
[self setFocusRingType:NSFocusRingTypeExterior];
[self setDrawsBackground:NO];
[[self cell] setRefusesFirstResponder:NO]; // accept 1st responder.
[[self cell] setShowsFirstResponder: YES];
}
If I use Apple's focus-ring APIs, the focus-ring is drawn as if the
text-view has not been zoomed. And it is shifted downward from it's
correct location.
- (void)drawFocusRingMask
{
// Set the focus ring mask to the zoomed bounds.
NSRectFill([self focusRingMaskBounds]);
}
- (NSRect)focusRingMaskBounds
{
return [self bounds];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden