views:

23

answers:

1

Hello,

I am trying to understand the meaning of clipRect in a table view embedded inside a scroll view. I assumed that the clip rect is the visible portion of the table view. This means that the width of the rect should not change as long as the table view is not resized, but upon monitoring the width of the clip rect in the following code, I noticed that the width changes as I move the horizontal scroll bar left to right. The width value becomes normal when I move the vertical scroll bar up and down.

Can someone explain this? Thanks in advance.

- (void)drawRow:(NSInteger)rowIndex clipRect:(NSRect)clipRect { 
    NSLog(@"drawRow Clip Rect Width:%f Height:%f", clipRect.size.width, clipRect.size.height);
    [super drawRow:rowIndex clipRect:clipRect];
}
A: 

This method is for drawing cells in a row. The clip rect determines the portion of the row to be drawn. Without further research I assume that it always encloses complete cells and not exactly the visible portion. This makes determining which cells to draw and the drawing itself much easier. If you scroll left to right different cells with different widths might become visible or may get hidden. The full width of all (even partially) visible cells in a row of your table view should sum up the width of that clip rect.

Max Seelemann
Alternatively, `clipRect` might only be the area that's just become visible since the last drawing cycle, not including any area that was visible then and is still visible.
Peter Hosey
Right, that could well be. I think it's actually more probable since NSTableView is quite an optimized control.
Max Seelemann
Yes clipRect is the area that's just become visible. Thanks.
David