« Tiger and the keyboard | Main | Debugging OCTest bundles »
June 19, 2005
Drawing a “mail like” border on items in an NSTableView
Mail has a cool way of making unread messages stand out. It is really easy to do this type of thing with NSTableView/NSOutlineView. Subclass the one you want, and override drawRow. Toss in the code you see below, and it should give a cool highlight on all expandable rows in an NSOutlineView (you will have to modify it to have it work in NSTableView -- just remove the call to isExpandable).
- (void)drawRow:(int)row clipRect:(NSRect)clipRect {
if (([self isExpandable:[self itemAtRow:row]]) && (![self isRowSelected:row])) {
// Draw a light-blue “mail like” border around the row, if not selected
NSRect rect = [self rectOfRow:row];
[[[NSColor blueColor] colorWithAlphaComponent:50/255.0] set];
NSBezierPath *path = [NSBezierPath bezierPath];
[path setLineCapStyle:NSRoundLineCapStyle];
[path setLineWidth:rect.size.height - 3];
int rowLevel = [self levelForRow:row];
float x = rect.origin.x + 10.0 + (rowLevel * [self indentationPerLevel]);
float y = rect.origin.y + (rect.size.height / 2.0);
[path moveToPoint:NSMakePoint(x,y)];
[path lineToPoint:NSMakePoint(x + rect.size.width - 2*10.0, y)];
[path stroke];
}
[super drawRow:row clipRect:clipRect];
}
Posted by corbin at June 19, 2005 02:37 PM
Comments
Awesome!! :-)
Posted by: Davey at June 19, 2005 04:48 PM
I think Borland's worldwide domination plan is to infiltrate every software company in existence and make them produce software that can be integrated with existing or future Borland products.
Case in point: Anders goes Microsoft and produces the .NET Framework, so that Borland can conquer .NET with Delphi.
You go to Apple, and probably shortly, we'll have a product that can conquer the Apple platform.
PS: For you other non-Borland readers, I'm joking!
Posted by: Chee Wee at June 19, 2005 08:41 PM
The line width used in Mail.app is bigger. It fills the entire row; so I guess the "- 3" is not needed.There is a one-pixel space between rows in a NSTableView (and thus outline view) by default anyway.
Posted by: Denis Defreyne at July 27, 2005 05:41 PM