Remove some magic numbers.

This commit is contained in:
LIU Dongyuan / 柳东原
2015-02-03 12:57:04 -08:00
parent 3be76bd57a
commit d300bdba4a
3 changed files with 6 additions and 2 deletions

View File

@@ -10,6 +10,8 @@
@interface QSHStatusItemView : NSButton
#define MENUBAR_FONT [NSFont menuBarFontOfSize:14.0]
@property (nonatomic, weak) NSStatusItem *statusItem;
@property (nonatomic) BOOL itemHighlighted; // differentiate from NSControls highlighted
@property (nonatomic) NSImage *icon;

View File

@@ -60,7 +60,7 @@
iconFrame = NSMakeRect(3, yOffset, 20, 20);
NSColor *color = self.itemHighlighted ? [NSColor whiteColor] : [NSColor blackColor];
NSDictionary *barTextAttributes = @{
NSFontAttributeName: [NSFont systemFontOfSize:14.0],
NSFontAttributeName: MENUBAR_FONT,
NSForegroundColorAttributeName: color
};
[self.label drawInRect:NSMakeRect(25, 2, NSWidth(self.bounds) - 30, 20) withAttributes:barTextAttributes];

View File

@@ -216,13 +216,15 @@ static const NSInteger kPreferencesDefaultHeight = 192;
- (void)changeLabel:(NSString *)label
{
NSDictionary *barTextAttributes;
if (IS_PERIOR_TO_10_9) {
self.statusItemView.label = label;
barTextAttributes = @{NSFontAttributeName: MENUBAR_FONT};
}
else {
self.statusItem.title = label;
barTextAttributes = @{NSFontAttributeName: self.statusItem.button.font};
}
NSDictionary *barTextAttributes = @{NSFontAttributeName: [NSFont systemFontOfSize:14.0]};
// 20 is image width, 10 is extra margin
self.statusItem.length = 20 + [label sizeWithAttributes:barTextAttributes].width + 10;
}