Various fixes in CPMenu

- No shadow when hightlighted (like Cocoa)
- Themable separator color/text color/shadow color
This commit is contained in:
Antoine Mercadal
2013-01-30 17:04:11 -08:00
parent 42eb4e2da1
commit bfb85ccfd2
4 changed files with 29 additions and 21 deletions
+3 -1
View File
@@ -22,6 +22,8 @@
@import "CPView.j"
@class _CPMenuItemStandardView
@implementation _CPMenuItemSeparatorView : CPView
{
@@ -52,7 +54,7 @@
CGContextMoveToPoint(context, CGRectGetMinX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
CGContextSetStrokeColor(context, [CPColor lightGrayColor]);
CGContextSetStrokeColor(context, [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-item-separator-color" forClass:_CPMenuItemStandardView]);
CGContextStrokePath(context);
}
+20 -18
View File
@@ -29,11 +29,10 @@
CPMenuItem _menuItem @accessors(property=menuItem);
CPFont _font;
CPColor _textColor;
CPColor _textShadowColor;
CGSize _minSize @accessors(readonly, property=minSize);
BOOL _isDirty;
BOOL _highlighted;
CPImageView _stateView;
_CPImageAndTextView _imageAndTextView;
@@ -48,16 +47,18 @@
+ (id)themeAttributes
{
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], 3.0, 17.0, 14.0, 17.0, 4.0, 30.0]
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], [CPNull null], 3.0, 17.0, 14.0, 17.0, 4.0, 30.0]
forKeys:[ @"submenu-indicator-color",
@"menu-item-selection-color",
@"menu-item-text-shadow-color",
@"menu-item-text-color",
@"menu-item-default-off-state-image",
@"menu-item-default-off-state-highlighted-image",
@"menu-item-default-on-state-image",
@"menu-item-default-on-state-highlighted-image",
@"menu-item-default-mixed-state-image",
@"menu-item-default-mixed-state-highlighted-image",
@"menu-item-separator-color",
@"left-margin",
@"right-margin",
@"state-column-width",
@@ -121,7 +122,10 @@
if (![_menuItem isEnabled])
return [CPColor lightGrayColor];
return _textColor || [CPColor colorWithCalibratedRed:70.0 / 255.0 green:69.0 / 255.0 blue:69.0 / 255.0 alpha:1.0];
if (_highlighted)
return [CPColor whiteColor];
return [self valueForThemeAttribute:@"menu-item-text-color"];
}
- (CPColor)textShadowColor
@@ -129,7 +133,10 @@
if (![_menuItem isEnabled])
return nil;
return _textShadowColor || [CPColor colorWithWhite:1.0 alpha:0.8];
if (_highlighted)
return nil;
return [self valueForThemeAttribute:@"menu-item-text-shadow-color"];
}
- (void)setFont:(CPFont)aFont
@@ -263,29 +270,24 @@
if (![_menuItem isEnabled])
return;
_highlighted = shouldHighlight;
[_imageAndTextView setTextColor:[self textColor]];
[_keyEquivalentView setTextColor:[self textColor]];
[_imageAndTextView setTextShadowColor:[self textShadowColor]];
[_keyEquivalentView setTextShadowColor:[self textShadowColor]];
if (shouldHighlight)
{
[self setBackgroundColor:[self valueForThemeAttribute:@"menu-item-selection-color"]];
[_imageAndTextView setImage:[_menuItem alternateImage] || [_menuItem image]];
[_imageAndTextView setTextColor:[CPColor whiteColor]];
[_keyEquivalentView setTextColor:[CPColor whiteColor]];
[_submenuIndicatorView setColor:[CPColor whiteColor]];
[_imageAndTextView setTextShadowColor:[self valueForThemeAttribute:@"menu-item-text-shadow-color"]];
[_keyEquivalentView setTextShadowColor:[self valueForThemeAttribute:@"menu-item-text-shadow-color"]];
[_submenuIndicatorView setColor:[self textColor]];
}
else
{
[self setBackgroundColor:nil];
[_imageAndTextView setImage:[_menuItem image]];
[_imageAndTextView setTextColor:[self textColor]];
[_keyEquivalentView setTextColor:[self textColor]];
[_submenuIndicatorView setColor:[self valueForThemeAttribute:@"submenu-indicator-color"]];
[_imageAndTextView setTextShadowColor:[self textShadowColor]];
[_keyEquivalentView setTextShadowColor:[self textShadowColor]];
}
if ([[_menuItem menu] showsStateColumn])
+3 -1
View File
@@ -2577,11 +2577,13 @@ var themedButtonValues = nil,
[
[@"submenu-indicator-color", [CPColor grayColor]],
[@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]],
[@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]],
[@"menu-item-text-color", [CPColor colorWithHexString:@"333333"]],
[@"menu-item-text-shadow-color", [CPColor colorWithWhite:1.0 alpha:0.8]],
[@"menu-item-default-off-state-image", nil],
[@"menu-item-default-off-state-highlighted-image", nil],
[@"menu-item-default-on-state-image", menuItemDefaultOnStateImage],
[@"menu-item-default-on-state-highlighted-image", menuItemDefaultOnStateHighlightedImage],
[@"menu-item-separator-color", [CPColor lightGrayColor]],
[@"menu-item-default-mixed-state-image", nil],
[@"menu-item-default-mixed-state-highlighted-image", nil],
[@"left-margin", 3.0],
+3 -1
View File
@@ -2012,11 +2012,13 @@ var themedButtonValues = nil,
[
[@"submenu-indicator-color", [CPColor grayColor]],
[@"menu-item-selection-color", [CPColor colorWithHexString:@"5C85D8"]],
[@"menu-item-text-shadow-color", [CPColor colorWithCalibratedRed:26.0 / 255.0 green: 73.0 / 255.0 blue:109.0 / 255.0 alpha:1.0]],
[@"menu-item-text-color", [CPColor colorWithHexString:@"333333"]],
[@"menu-item-text-shadow-color", [CPColor colorWithWhite:1.0 alpha:0.8]],
[@"menu-item-default-off-state-image", nil],
[@"menu-item-default-off-state-highlighted-image", nil],
[@"menu-item-default-on-state-image", menuItemDefaultOnStateImage],
[@"menu-item-default-on-state-highlighted-image", menuItemDefaultOnStateHighlightedImage],
[@"menu-item-separator-color", [CPColor colorWithHexString:@"DFDFDF"]],
[@"menu-item-default-mixed-state-image", nil],
[@"menu-item-default-mixed-state-highlighted-image", nil],
[@"left-margin", 3.0],