Skip to content

Commit

Permalink
Various fixes in CPMenu
Browse files Browse the repository at this point in the history
- No shadow when hightlighted (like Cocoa)
- Themable separator color/text color/shadow color
  • Loading branch information
primalmotion committed Jan 31, 2013
1 parent 42eb4e2 commit bfb85cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
4 changes: 3 additions & 1 deletion AppKit/CPMenuItem/_CPMenuItemSeparatorView.j
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

@import "CPView.j"

@class _CPMenuItemStandardView


@implementation _CPMenuItemSeparatorView : CPView
{
Expand Down Expand Up @@ -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);
}

Expand Down
38 changes: 20 additions & 18 deletions AppKit/CPMenuItem/_CPMenuItemStandardView.j
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -121,15 +122,21 @@
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
{
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
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 3 additions & 1 deletion AppKit/Themes/Aristo/ThemeDescriptors.j
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 3 additions & 1 deletion AppKit/Themes/Aristo2/ThemeDescriptors.j
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit bfb85cc

Please sign in to comment.