Re: NSTableView and Ellipses--Again
Re: NSTableView and Ellipses--Again
- Subject: Re: NSTableView and Ellipses--Again
- From: Jasper Touwen <email@hidden>
- Date: Sun, 11 Aug 2002 11:12:15 +0200
Since i am also a newbie, i can only do some suggestions...
use a formatter...
allocate a private var NSMutableString, so no need for allocation it
with a default capacity or length...for example 50 chars...
do the size calculation by splitting in half..
so: fist calculate complete string...
second calculate the half of the string...
then calculate the half of the half etc...
And last: look for glyphs, or something like that
Maybe you can use NSLayoutManager method: -
(unsigned)characterIndexForGlyphAtIndex:(unsigned)glyphIndex
Hopefully this will help in getting more comments...or at least new
idea's...
Jasper.
On Sunday, August 11, 2002, at 03:46 AM, Buzz Andersen wrote:
>
All,
>
Since I got no responses on my last post about this, I thought I'd post
>
again--this time with a slightly different question...
>
>
As I said in my last message, I am trying to implement the functionality
>
found in iTunes' table view that causes it to truncate strings which
>
are too
>
long to fit within in a column and place ellipses (...) at the end of
>
the
>
visible part.
>
>
Below is the code I'm using, which I am not very fond of.
>
Essentially, I
>
iterate through each character in the string, add the current character
>
to
>
the end of an NSMutableAttributedString, and use the size method in that
>
class to determine if the attributed string has reached a length yet
>
that
>
would be too long for the column. If it has, I add the ellipses in the
>
proper place.
>
>
I know that this is an ugly way to do it, and it seems to contribute to
>
noticeable sluggishness as the user moves through the table view (the
>
code
>
is called over and over by the "willDisplayCell" delegate method).
>
>
Does anyone have any ideas about a better way to do it? I know it must
>
be
>
possible to create *something* more efficient, because iTunes' table
>
view
>
doesn't seem to suffer the kind of sluggishness I'm seeing...
>
>
Any advice anyone could offer would be most appreciated!
>
>
Thanks,
>
Buzz
>
>
--- BEGIN CODE ---
>
>
if (stringSize.width > columnWidth) {
>
result = [[NSMutableAttributedString alloc] init];
>
>
for (i = 0; i < [attString length]; i++) {
>
[result appendAttributedString: [attString
>
attributedSubstringFromRange: NSMakeRange(i, 1)]];
>
>
if ([result size].width > columnWidth) {
>
[result replaceCharactersInRange: NSMakeRange(i - 2,
>
[result
>
length] - (i - 2)) withString: @"..."];
>
break;
>
}
>
}
>
>
[result autorelease];
>
return [result string];
>
}
>
else {
>
return [attString string];
>
}
>
>
--- END CODE ---
>
_______________________________________________
>
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.