Re: NSTableView - Alternating blue and white background
Re: NSTableView - Alternating blue and white background
- Subject: Re: NSTableView - Alternating blue and white background
- From: "Erik J. Barzeski" <email@hidden>
- Date: Tue, 17 Dec 2002 12:50:28 -0500
Hi,
Stephane said:
>
>> One solution is described in some Mac Tech articles written by Dan
>
>> Wood. The code is available on his web site and IIRC, if you search
>
>> the
>
>> archive you should find a post indicating the URL of the source codes.
>
>
>
> Unfortunately, this method is subject to rounding errors, so if you
>
> expect
>
> to have a few hundred (or more) rows in the table view, eventually the
>
> colors won't line up. You'll have a line that's half blue, half white,
>
> etc.
>
>
Interesting. With how many lines are you seeing this side effect? I'm
>
using another method similar to that one so I may be affected by this
>
bug too. I tested with a hundred cells or so and didn't see this.
I don't recall the specifics, but it worked out to about 500. Let me see if
I can re-enable it quickly...
Hmm, actually even around the 70th row it's clearly visible. Perhaps I
didn't re-set everything, but, here's what it looks like:
http://iacas.org/asm/misaligned.gif
>
> Overriding the table cell drawing method is what we had to use in
>
> MailDrop.
>
>
But when the table is empty, there is no stripped background?
Correct. And your intercell spacing has to be 0, I believe, or you get
little white gaps. That's the downside, yes.
Here's the code I believe I got right from Dan Wood's tutorial. Perhaps I'd
made a typo, but this is the code used to generate the misaligned table view
colored rows above:
{
NSColor *evenColor = [NSColor colorWithCalibratedRed:0.929 green:0.953
blue:0.996 alpha:1.0];
NSColor *oddColor = [NSColor whiteColor];
float rowHeight = [self rowHeight] + [self intercellSpacing].height;
NSRect visibleRect = [self visibleRect];
NSRect highlightRect;
highlightRect.origin = NSMakePoint(NSMinX(visibleRect),
(int)(NSMinY(clipRect))/rowHeight);
highlightRect.size = NSMakeSize(NSWidth(visibleRect), rowHeight - [self
intercellSpacing].height);
while(NSMinY(highlightRect) < NSMaxY(clipRect))
{
NSRect clippedHighlightRect = NSIntersectionRect(highlightRect,
clipRect);
int row = (int)((NSMinY(highlightRect)+rowHeight/2.0)/rowHeight);
NSColor *rowColor = (0 == row % 2) ? evenColor : oddColor;
[rowColor set];
NSRectFill(clippedHighlightRect);
highlightRect.origin.y += rowHeight;
}
[super highlightSelectionInClipRect:clipRect];
}
--
Best wishes,
Erik J. Barzeski
Any fool can know. The point is to understand. - Albert Einstein
###################################################################
Email: erik@(anything below) AIM: iacas
http://iacas.org http://weims.net
http://techstra.net http://barzeski.com
http://cocoadevcentral.com http://soundsetcentral.com
http://freshlysqueezedsoftware.com http://applescriptcentral.com
###################################################################
_______________________________________________
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.