views:

47

answers:

2

I'm trying to assemble a NSTextView by hand as in Apple's TextSizingExample and found a boring bug. If you run TextSizingExample and select "Wrapping Scrolling Text" mode, then you'll see the text being partially hidden by a vertical scrollbar. Tried to play with the size and autoresizing mask of text container and text view but it didn't help.

+1  A: 

The problem is in the VerticalScrollAspect class's naive approach to creating the scroll view. In the -containerView method, there is the following line:

scrollView = [[NSScrollView alloc] initWithFrame:[documentView frame]];

Unfortunately, this does not account for the width of the vertical scroll bar or the border style of the scroll view, both of which are important to consider.

Joshua Nozzi
Thank you, Joshua, it helped.
Indoor
A: 

You are dealing with three components: the containing window or view, the scrollview and the textview inside the scrollview. The scrollview should be initialized to fit into the frame or bounds of the view or window in which it will be displayed, the textview only needs to know where the content area of scrollview is located. Thus:

NSScrollView *scrollView = [[[NSScrollView alloc] initWithFrame:[containingView bounds]] autorelease];

NSSize contentSize = [scrollView contentSize];
NSTextView *textView = [[[NSTextView alloc] initWithFrame:NSMakeRect(0, 
         0,
         contentSize.width, 
         contentSize.height)
      ] autorelease];
Elise van Looij
While certainly true, this doesn't address the issue with the demo, which was the OP's concern. In the demo, the order in which these nested views are created is set up such that the scroll view is being (naively) sized for the text view, instead of the other way around.
Joshua Nozzi