Re: Shared NSTextView
Re: Shared NSTextView
- Subject: Re: Shared NSTextView
- From: Graham Cox <email@hidden>
- Date: Tue, 19 Aug 2008 15:22:16 +1000
You can share a few things. The NSTextView can be shared since
presumably it will only be possible to edit one object at a time
(otherwise it's going to get a bit confusing for the poor old user).
You could also use NSWindow's field editor for this, which is what
text fields in dialogs use. For laying out text in the boxes, you can
re-use the NSLayoutManager since it only comes into play while you
draw the text and each box is drawn one at a time. The text container
can also be reused, or more simply, just created on the fly each time
- it doesn't do much so there's very little overhead involved (or
conversely, very little to be gained by reusing it).
That said, don't over-optimise before you have it working.
Incidentally, my DrawKit framework includes text objects that do
exactly what you describe - you can download it and see what I did if
you want (or use the framework ;-). I don't use the field editor as it
happens, but instead re-use a shared NSTextView on the fly to edit a
text object. I do share the NSLayoutManager. The NSLayoutManager is
internal so it's just returned as a shared object from a class method
of my text object. The editing text view is a feature of the main
drawing view. When the text object needs to edit itself, it grabs the
editing view instance from the current view and sets it up positioned
and sized to match the object, and puts its text into it.
http://apptree.net/drawkitmain.htm
hth,
cheers, Graham
On 19 Aug 2008, at 2:46 pm, Oleg Krupnov wrote:
I am developing a custom view, sort of a simple graphic editor, where
the user can draw graphic boxes of different size. Each box should
display its own attributed string bounded by its own size, and when
the user double-clicks any box, he becomes able to edit the box's text
in-place.
I have read the docs and have a general understanding of the text
system components: NSTextStorage, NSLayoutManager, NSTextContainer and
NSTextView.
However I wonder if some instances of these can be shared across
different graphic boxes for better efficiency?
I could go the simple and dull way and create a separate instance of
NSTextView for each box, but I am afraid this could be a waste of
resources, because layout manager is costy. Also, most of time I only
need to display text in boxes, not to edit it.
I thought it could be smarter to create a single shared instance of
NSTextView per custom view, and re-attach it to different boxes when
the user double-clicks a box. The rest of time I'd use NSTextStorage
and NSTextContainer to just draw the string. Is this a good idea? In
this case, what object instances should each graphic box have of its
own? My guess is that each graphic box should have its own instances
of NSTextStorage and NSTextContainer, but I am not sure what about
NSLayoutManager? Can it be shared too, or it's going to be
inefficient? How do I reconnect the shared components from a box to
another box?
_______________________________________________
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