开发者

NSTextView and NSTextContainer size & clipping area

开发者 https://www.devze.com 2023-03-04 03:17 出处:网络
I found very interesting behavior of text container inside NSTextView. When i set size of container so it less than size of NSTextView frame and try

I found very interesting behavior of text container inside NSTextView. When i set size of container so it less than size of NSTextView frame and try draw any figures (like lines, rectangles) in NS开发者_JAVA技巧TextView drawRect: , all my figures clipped to size of text container.

So, frame size of NSTextView "allows" me to use it for drawing, but seems that is limited to container size.

If there are any possibility to draw inside text view but outside of text container ?

Code in Custom NSTextView - (void) drawRect:

[super drawRect:dirtyRect];

NSBezierPath* aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(100, 100)];
[aPath lineToPoint:NSMakePoint(500, 100)];
[aPath stroke];

Custom textview resize policy set, so it resizes in all dimensions with container. This is code for custom NSTextView

- (void) setFrameSize:(NSSize)newSize {

    [super setFrameSize:newSize];

    NSTextContainer *container = [self textContainer];
    newSize.width -= 200;
    [container setContainerSize:newSize];
}


Thanks Ross Carter for advice:

Try wrapping the call to super like this:

[NSGraphicsContext saveGraphicsState];
[super drawRect:rect];
[NSGraphicsContext restoreGraphicsState];
0

精彩评论

暂无评论...
验证码 换一张
取 消