Skip navigation.
 
mlRe: NSTableView - Alternating blue and white background
FROM : Erik J. Barzeski
DATE : Tue Dec 17 20:51:01 2002

I posted my source. Feel free to compare. I assume at this poitn that the
error most likely lies with myself. I've set the intercell spacing to 0 in
an init method, and changed the size of the font, but outside of that, I
don't know what could be different.

On 12/17/02 2:31pm, "Joe Lester" <<email_removed>> wrote:
> Interesting. I use the same basic method that Dan Wood described in his
> November MacTech article in my NSTableView subclass. I've provided up to 8000
> rows to my NSTableView subclass with no visible row color misalignment. Maybe
> I'm doing something different?
>
> Here's my source. It's drifted some from the example in Dan Wood's article but
> my impression is that it should not really be that different. If there are
> rounding errors, I'd like to eliminate them, if possible:
>
> - (void)highlightSelectionInClipRect:(NSRect)clipRect
> /*"
>  Overridden to draw the proper background color on the rows.
>  Sends tableView:stripeColorForRow: to the data source to get
>  the color for each visible row. If the data source does not
>  respond, it stripes odd rows.
> "*/
> {
>  //Get dims from self
>  float rowHeight = [self rowHeight] + [self intercellSpacing].height;
>  NSRect visibleRect = [self visibleRect];

>  //Calculate the rect we should highlight
>  NSRect highlightRect;
>  highlightRect.origin = NSMakePoint(NSMinX(visibleRect),
> (int)(NSMinY(clipRect)/ rowHeight) * rowHeight);
>  highlightRect.size = NSMakeSize(NSWidth(visibleRect), rowHeight );

>  //Do the drawing
>  while (NSMinY(highlightRect) < NSMaxY(clipRect))
>  {
>      NSColor *rowColor;
>      NSRect clipedHighlightRect = NSIntersectionRect(highlightRect,
> clipRect);
>      int row = (int)((NSMinY(highlightRect) + rowHeight / 2.0) / rowHeight);
>     
>      if ([self dataSource] &&
> [[self dataSource]
> respondsToSelector:@selector(tableView:stripeColorForRow:)])
>      {
>          NSColor *colorFromDataSource = [[self dataSource] tableView:self
> stripeColorForRow:row];
>          rowColor = (colorFromDataSource) ? colorFromDataSource : [NSColor
> whiteColor];
>      }
>      else
>      {
>          rowColor = (0 == row % 2) ? [NSColor colorWithCalibratedRed:0.929
> green:0.953 blue:0.996 alpha:1.0] : [NSColor whiteColor];
>      }
>     
>      [rowColor set];
>      NSRectFill(clipedHighlightRect);
>      highlightRect.origin.y += rowHeight;
>  }

>  [super highlightSelectionInClipRect:clipRect];
> }



--
    Kindest regards,
    Erik J. Barzeski

You know you're a geek when your friends are dating women whose
Web pages say this: The purpose of this page is to provide students
with a closer look at the implementation of a pipelined processor.
###################################################################
Email: erik@(anything below)        AIM: iacas

                    <A href="http://weims.net">http://weims.net
                  <A href="http://barzeski.com">http://barzeski.com
          <A href="http://soundsetcentral.com">http://soundsetcentral.com
  <A href="http://applescriptcentral.com">http://applescriptcentral.com
###################################################################
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSTableView - Alternating blue and white background Flemming Bengtsson Dec 17, 10:53
mlRe: NSTableView - Alternating blue and white background David Remahl Dec 17, 11:03
mlRe: NSTableView - Alternating blue and white background Warren.Burton Dec 17, 11:03
mlRe: NSTableView - Alternating blue and white background Cristi Savu Dec 17, 11:05
mlRe: NSTableView - Alternating blue and white background j o a r Dec 17, 11:15
mlRe: NSTableView - Alternating blue and white background j o a r Dec 17, 11:38
mlRe: NSTableView - Alternating blue and white background Stéphane Sudre Dec 17, 11:38
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 16:04
mlRe: NSTableView - Alternating blue and white background Joe Lester Dec 17, 17:15
mlRe: NSTableView - Alternating blue and white background Stéphane Sudre Dec 17, 17:19
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 18:50
mlRe: NSTableView - Alternating blue and white background Joe Lester Dec 17, 20:31
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 20:51
mlRe: NSTableView - Alternating blue and white background John C. Randolph Dec 17, 20:53