Re: Custom Text View
Re: Custom Text View
- Subject: Re: Custom Text View
- From: "Ujwal S. Sathyam" <email@hidden>
- Date: Fri, 23 Jan 2004 17:39:19 -0800 (PST)
I have been working on a very similar situation. In my case, the
application is a terminal emulator (iTerm.app), and it currently uses
NSTextView to draw the text. However, that is quite slow, so I did end up
building my own text view by subclassing:
NSTypesetter
NSTextStorage
NSLayoutManager
You can download and look at the iTerm sources if you like.
Most of the subclassing is the in typesetter since a terminal emulator
really needs very little typesetting, so I removed a lot of overhead
there. There is still quite a bit of overhead in drawing and maybe glyph
conversion, and I have just started to tackle sublcassing NSLayoutManager.
Maybe using a NSTextView class/subblass is not ideal for a high speed
display of text, but it offers really other very convenient features such
as text selection, as you mentioned, and I would rather not have to
recreate all that.
But still, I have found the inner workings of the text system very hard to
understand. I have heard about ATSUI, but I don't know how that plays into
the scheme of things, but I will probably look into that also.
In terms of display, Terminal.app is quite a bit faster than iTerm.app,
and it also seems that it uses a custom view. I wonder if it uses the
Cocoa text system at all, or whether it does its own drawing. Maybe
someone on this list can enlighten me on that?
Ujwal
-----------------------------------------------------------------------
I'm currently stuck in the dilemma that NSTextView seems slow when it
comes to quickly updating text by appending to it. It seems to do
display updates as one large chunk of text if -insertText is called
line by line. I'd rather have it insert the line, display it, then
insert the next and so forth - ending up with the effect that it's
scrolling smoothly rather then as one long 'jolt'.
To fix this, I've decided to take to writing my own text view which
will hopefully draw faster and in the method I'd prefer. I've looked at
NSLayoutManager and NSTextStorage/Container and feel confident that
using a custom NSView with these three objects is the way to go.
NSTextStorage's -drawInRect: method seems the best way to go since it
manages line wrapping on it's own as opposed to NSLayoutManager's glyph
drawing (though NSLayoutManager's method is slightly faster, I'd
probably lose that time plus some wrapping it properly)
What I was planning on doing is just drawing enough to fill the bounds
in my drawRect: method and stopping there without rendering the other
text. Since my view will just keep an array of lines, removing the
first line shouldn't be a problem since the view will not have to deal
with it unlike NSTextView which recalculates the entire view if the
characters change.
My only major concerns are these:
1) Using drawInRect: will obviously break text selection for the user
to copy from it. Does anyone know if/how it would be possible to
restore this functionality?
2) Are there any downsides to doing this? Or has anyone done this
before? I'd like to not have to rewrite NSTextView or something else
that's been done before but it's looking like it's the only way to get
the features I want
3) How will NSScrollView take to this concept? Will I have to manually
control it's size and positioning in relation to my array which will
range from anywhere between 0 and 1024 objects long? As an aside, I'll
probably forego live dragging in lieu of faster draw times, so I really
only need be concerned with what its position is at mouseUp:
Regards,
~Anthony Duer
_______________________________________________
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.