Skip to content

Commit

Permalink
Added a themed attribute for round rect selection of rows.
Browse files Browse the repository at this point in the history
Selections in the tableview can now have round corners. The default is a regular
rect, but if the selecction radius is changed. Nice good looking round rect
selections will appear.
  • Loading branch information
mrcarlberg committed May 11, 2012
1 parent c437537 commit 183260d
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions AppKit/CPTableView.j
Expand Up @@ -257,8 +257,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null]]
forKeys:["alternating-row-colors", "grid-color", "highlighted-grid-color", "selection-color", "sourcelist-selection-color", "sort-image", "sort-image-reversed"]];
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null]]
forKeys:["alternating-row-colors", "grid-color", "highlighted-grid-color", "selection-color", "sourcelist-selection-color", "sort-image", "sort-image-reversed", "selection-radius"]];
}

- (id)initWithFrame:(CGRect)aFrame
Expand Down Expand Up @@ -794,6 +794,26 @@ NOT YET IMPLEMENTED
return [self currentValueForThemeAttribute:@"selection-color"];
}

/*!
Sets the highlight radius for a row or column selection.
@param aRadius a int
*/
- (void)setSelectionHighlightRadius:(int)aRadius
{
[self setValue:aRadius forThemeAttribute:"selection-radius"];

[self setNeedsDisplay:YES];
}

/*!
Returns the highlight radius for a row or column selection.
*/
- (int)selectionHighlightRadius
{
return [self currentValueForThemeAttribute:@"selection-radius"];
}

/*!
Sets the highlight gradient for a row or column selection
Expand Down Expand Up @@ -3773,7 +3793,24 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
CGContextStrokePath(context);
}
else
CGContextAddRect(context, rowRect);
{
var radius = [self selectionHighlightRadius];
if (radius > 0)
{
var minX = CGRectGetMinX(rowRect),
maxX = CGRectGetMaxX(rowRect),
minY = CGRectGetMinY(rowRect),
maxY = CGRectGetMaxY(rowRect);

CGContextMoveToPoint(context, minX + radius, minY);
CGContextAddArcToPoint(context, maxX, minY, maxX, minY + radius, radius);
CGContextAddArcToPoint(context, maxX, maxY, maxX - radius, maxY, radius);
CGContextAddArcToPoint(context, minX, maxY, minX, maxY - radius, radius);
CGContextAddArcToPoint(context, minX, minY, minX + radius, minY, radius);
}
else
CGContextAddRect(context, rowRect);
}
}

CGContextClosePath(context);
Expand Down

0 comments on commit 183260d

Please sign in to comment.