Re: +[NSColor highlightColor] in NSTableView
Re: +[NSColor highlightColor] in NSTableView
- Subject: Re: +[NSColor highlightColor] in NSTableView
- From: Corbin Dunn <email@hidden>
- Date: Mon, 02 Feb 2009 08:33:00 -0800
On Feb 1, 2009, at 2:41 PM, Graham Cox wrote:
On 2 Feb 2009, at 1:46 am, Jerry Krinock wrote:
+[NSColor selectedTextBackgroundColor] definitely gives a color
based on System Preferences > Appearance > Highlight Color (for
selected text). However, the color actually used in NSTableView is
darker than this.
For example, I set the color in System Preferences to RGB = {255,
0, 255}, but when I use DigitalColor Meter.app on a highlighted
cell in a "stock" NSTableView, I measure {204, 0, 204}. Now,
204=51*4 and 255=51*5. So it looks like someone in the
NSTextFieldCell Department decided to reduce the brightness by 20%,
because, of course, if someone set their "highlight" (sic) color to
all white, the white text drawn on it by NSTextFieldCell would be
invisible.
So, I was able to match the "stock" NSTextFieldCell using a little
brightness-tweaking method that I had lying around. Is this 20%
reduction in brightness documented anywhere? I even searched Human
Interface Guldelines for "highlight" but didn't find any mention of
this.
Interestingly, in NSTextViews (TextEdit docs, this message in
Mail.app), the text is drawn in black instead of white, and the 20%
reduction is not applied. And then, Xcode's editor ignores my
System Preferences and uses black on orange, like it or not. Seems
like we need some User Interface Police here.
***************************************************
color = [NSColor selectedTextBackgroundColor] ;
color = [color colorTweakBrightness:-.20] ;
Just to make sure you're aware of it, but -[NSColor
shadowWithLevel:] (and its sister method, -[NSColor
highlightWithLevel:]) are darkening and brightening methods that
NSColor has - there's no need to write your own unless they're doing
something unusually funky.
I can't shed any light on what NSTableView uses, maybe Corbin could
let you know? (I modified the title of the message so he might
notice it ;-)
Good call; I have a Smart Folder to only show things with "TableView/
OutlineView and SavePanel/OpenPanel" in the title. That's a hint to
people with questions on those subjects.
The blue-highlight color that NSTableView uses is this:
+ (NSColor *)alternateSelectedControlColor; // Similar to
selectedControlColor; for use in lists and tables
Note: for custom cells, you may want to simply return nil from this
method to avoid having the NSCell do any background highlight color
drawing:
- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView;
That only works in NSTableViews; it won't work with cells in
NSBrowsers, which actually rely on this method to draw the
highlighting (since it is a matrix of cells).
corbin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden