Re: A line after a string
Re: A line after a string
- Subject: Re: A line after a string
- From: Jerry <email@hidden>
- Date: Tue, 23 Sep 2003 15:21:56 -0700
Neglected to send my first response to the list:
>
>
I think this is going to be more trouble than you were hoping, but
>
it's not too bad. You will need either to subclass NSTextView or
>
create a custom view that contains the text view. You can get the
>
location for your lines a couple of different ways, either using font
>
metrics or more directly through the layout manager for the text view.
>
It might look something like this for an NSTextView subclass (untested
>
code snippet, just to give the general idea):
>
>
- (void)drawRect:(NSRect)r
>
{
>
NSRect lineRect;
>
int lineBottom;
>
NSRect bounds = [self bounds];
>
[super drawRect:r]
>
>
int i = [self numberOfLines]; // numberOfLines is a method you
>
would write
>
for (; i >= 0 ; i--) {
>
NSRange lineRange = [self rangeForLine:i]; // rangeForLine is
>
a method you would write
>
lineRect = [[self layoutManager]
>
boundingRectForGlyphRange:lineRange inTextContainer:[self
>
textContainer]];
>
lineBottom = lineRect.y+lineRect.height; // text view will
>
be flipped, I think.
>
NSFrameRectWithWidth(NSMakeRect(bounds.x, lineBottom,
>
bounds.y, lineBottom), 1.0); // draw the line
>
}
>
}
>
>
The code would be very similar for a custom view that contained an
>
NSTextView. Depending what you are trying to do, using font metrics
>
may be more straightforward, but if your lines ever wrap or use
>
multiple fonts and sizes the layout manager will still give you the
>
right coordinates.
>
>
You may not want to use NSBezierPath to draw the line; in my
>
experience I couldn't get it to stop blending with the background. I
>
may have missed something, however.
>
>
Jerry
>
>
On Tuesday, September 23, 2003, at 10:33 AM, Sanri Parov wrote:
>
>
> Hi everybody,
>
>
>
> in an NSTextView I draw some strings without particular attributes.
>
> All
>
> the strings end with "\n".
>
> In the following line I'd like to draw a separator (NSBezierPath type)
>
> that goes along the entire width of the view, in order to visually
>
> keep
>
> informations organized.
>
> Is there a way to do this?
>
>
>
> Thank you.
>
>
>
> --
>
> Sanri Parov
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.