Corbin's Treehouse - Corbin Dunn, Santa Cruz, CA
Plug Bug
Treehouse
Photography
Videos
Shop
Unicycling
About

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).

mail_like_highlighting


- (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];
}

NOTE: use this at your own risk. I think resizing the thing doesn’t quite work.



One Response to “Drawing a “mail like” border on items in an NSTableView”

  1. Steve says:

    If it does not work in all cases, ie is robust, then it is not actually easy is it? Since of course you have not accomplished the task.

(c) 2008-2012 Corbin Dunn

Corbin's Treehouse is powered by WordPress. Made on a Mac.

Subscribe to RSS feeds for entries and comments.

17 queries. 0.898 seconds.


Fatal error: Call to undefined function akismet_counter() in /home/corbin_dunn/corbinstreehouse.com/blog/wp-content/themes/corbins-treehouse-white/footer.php on line 38