NSTextView's -setTextContainerInset: issues
NSTextView's -setTextContainerInset: issues
- Subject: NSTextView's -setTextContainerInset: issues
- From: Keith Blount <email@hidden>
- Date: Sun, 22 Oct 2006 04:37:30 -0700 (PDT)
Hello,
I have a text view that can be scaled by the user. In addition, the text view has "margins" around it that I create using -setTextContainerInset:. When I change the scaling, I update the text container inset to remain in proportion (so that it always looks about 20 pixels all around no matter what the scale is). However, it seems that scaling in conjunction with setting thet text container inset can create some weird redrawing bugs. When the text is scaled and there is a text container inset, if the user scrolls the text, there will be white horizontal lines through some of the lines of text, as though the visible area has not been redrawn correctly. This only happens when the user scrolls, the text is scaled, and there is an inset. If I set the text container inset to 0, everything works fine.
Investigating this, I was interested in this note in the docs under -setTextContainerInset:
Discussion
It is possible to set the text container and view sizes and resizing behavior so that the inset cannot be maintained exactly, although the text system tries to maintain the inset wherever possible. In any case, the textContainerOrigin and size of the text container are authoritative as to the location of the text container within the view.
Does this explain the behaviour I am seeing? Or is this a display bug in NSTextView? Does anybody know if there is anything I can do to work around this? The code I am using to scale the text view is included below.
Many thanks in advance,
Keith
Here is the code I use to scale the text view:
- (void)rescaleTextViewWithNewScale:(int)scalePercent
{
if (scalePercent == 0)
return;
float zoom = (float)scalePercent / 100.0;
NSRect textViewBounds = [textView frame];
textViewBounds.size.height = textViewBounds.size.height / zoom;
textViewBounds.size.width = textViewBounds.size.width / zoom;
[textView setBounds:textViewBounds];
// Ensure offset always looks about 20 pixels rather than getting bigger or smaller depending on scale
float scale = [textView frame].size.height/[textView bounds].size.height;
float insetWidth = (int)(20.0/scale);
float insetHeight = (int)(20.0/scale);
[textView setTextContainerInset:NSMakeSize(insetWidth,insetHeight)];
[textView sizeToFit];
[textView setFrameSize:[textView frame].size];
[textView setNeedsDisplayInRect:[textView visibleRect]];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden