Re: Displaying line numbers at the left of a subclass of NSTextView
Re: Displaying line numbers at the left of a subclass of NSTextView
- Subject: Re: Displaying line numbers at the left of a subclass of NSTextView
- From: Uli Kusterer <email@hidden>
- Date: Mon, 20 Aug 2007 15:59:19 +0200
On 20.08.2007, at 06:47, Ricardo Diaz wrote:
Hi, how can I implement a rectangle on the left of the text view
that displays the line numbers?
This question has been answered a couple times on this list. I
actually just implemented something like this yesterday. There are
more effective ways, but what I did was to put a view to the right of
the NSTextView. I look at the textContainerOffset, visibleRect of the
NSTextView and subscribe to bounds changed notifications on the
NSClipView owned by the enclosingScrollView of my text view. That
lets me update my view when the text view is scrolled.
To find out where to display my line numbers, I ask the
textContainer, which gives you info about which character index is at
which NSPoint and vice versa. Then I can compare that info to a list
of line starts/ends I've generated. The line starts/ends list has to
scan the whole text, which is kind of inefficient. You could probably
do better by subclassing the layout manager and somehow making it do
that once, but I haven't looked into stuff like that yet.
Most of this info was fairly easy to google up, and I encourage you
to do that, because the blog postings contain numerous details you'd
want to know.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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