Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates

  • Loading branch information...
commit 309de56558b77c10a91d4a4903bba06835aa03de 1 parent 2d7a5e1
@briancsinger authored
Showing with 38 additions and 9 deletions.
  1. +1 −1  MenuClocks/BSAppDelegate.m
  2. +37 −8 MenuClocks/StatusItemView.m
View
2  MenuClocks/BSAppDelegate.m
@@ -16,7 +16,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
-
+
[_statusItemView setNeedsDisplay:YES];
}
View
45 MenuClocks/StatusItemView.m
@@ -119,14 +119,26 @@ - (void)drawRect:(NSRect)dirtyRect
[_timeFormatter setTimeZone:tz.timeZone];
NSString *timeString = [NSString stringWithFormat:@"%@ ", [_timeFormatter stringFromDate:[NSDate date]], nil];
- [tz.caption drawWithRect:NSMakeRect(origin.x, (roundf(self.bounds.size.height / 2.0)) - 4, [timeString sizeWithAttributes:[self timeAttributes]].width, roundf(self.bounds.size.height / 2.0) + 4)
- options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine | NSLineBreakByClipping
- attributes:[self nameAttributes]];
+ NSRect timeRect = [[_timeFormatter stringFromDate:[NSDate date]] boundingRectWithSize:NSMakeSize(1e100, 1e100)
+ options:0
+ attributes:[self timeAttributes]];
+ NSRect nameRect = [tz.caption boundingRectWithSize:NSMakeSize(1e100, 1e100)
+ options:0
+ attributes:[self timeAttributes]];
- [timeString drawInRect:NSMakeRect(origin.x, 4, [timeString sizeWithAttributes:[self timeAttributes]].width, (roundf(self.bounds.size.height / 2.0) + 4)) withAttributes:[self timeAttributes]];
+ if (tz.showCaption) {
+ [tz.caption drawWithRect:NSMakeRect(origin.x, (roundf(self.bounds.size.height / 2.0)) - 4, (nameRect.size.width > timeRect.size.width) ? nameRect.size.width : timeRect.size.width, roundf(self.bounds.size.height / 2.0) + 4)
+ options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine | NSLineBreakByClipping
+ attributes:[self nameAttributes]];
+ }
-
- origin = NSMakePoint(origin.x + [timeString sizeWithAttributes:[self timeAttributes]].width, origin.y);
+ [timeString drawInRect:NSMakeRect(origin.x, 4, (tz.showCaption && nameRect.size.width > timeRect.size.width) ? nameRect.size.width : timeRect.size.width, (roundf(self.bounds.size.height / 2.0) + 4)) withAttributes:[self timeAttributes]];
+
+
+ float spacing = origin.x;
+ spacing += (tz.showCaption && nameRect.size.width > timeRect.size.width) ? nameRect.size.width : timeRect.size.width;
+
+ origin = NSMakePoint(spacing, origin.y);
}
}
}
@@ -151,19 +163,24 @@ - (NSColor *)nameForegroundColor {
- (NSDictionary *)nameAttributes {
- // Use default menu bar font size
+
NSFont *font = [NSFont fontWithName:@"Tahoma-Bold" size:12];
+
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[NSColor whiteColor]];
[shadow setShadowOffset:NSMakeSize(0, 1)];
[shadow setShadowBlurRadius:1];
+ NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
+ [paragraph setAlignment:NSCenterTextAlignment];
+
NSColor *foregroundColor = [self nameForegroundColor];
return [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
foregroundColor, NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
+ paragraph, NSParagraphStyleAttributeName,
nil];
}
@@ -173,9 +190,13 @@ - (NSDictionary *)timeAttributes {
NSColor *foregroundColor = [self titleForegroundColor];
+ NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
+ [paragraph setAlignment:NSCenterTextAlignment];
+
return [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
foregroundColor, NSForegroundColorAttributeName,
+ paragraph, NSParagraphStyleAttributeName,
nil];
}
@@ -189,7 +210,15 @@ - (NSRect)titleBoundingRect {
NSString *combined = @"";
for (BSTimeZoneConfig *tz in _timeZones) {
[_timeFormatter setTimeZone:tz.timeZone];
- combined = [NSString stringWithFormat:@"%@ %@", combined, [_timeFormatter stringFromDate:[NSDate date]], nil];
+
+ NSRect timeRect = [[_timeFormatter stringFromDate:[NSDate date]] boundingRectWithSize:NSMakeSize(1e100, 1e100)
+ options:0
+ attributes:[self timeAttributes]];
+ NSRect nameRect = [tz.caption boundingRectWithSize:NSMakeSize(1e100, 1e100)
+ options:0
+ attributes:[self timeAttributes]];
+
+ combined = [NSString stringWithFormat:@"%@ %@", combined, (tz.showCaption && nameRect.size.width > timeRect.size.width) ? tz.caption : [_timeFormatter stringFromDate:[NSDate date]], nil];
}
return [combined boundingRectWithSize:NSMakeSize(1e100, 1e100)
Please sign in to comment.
Something went wrong with that request. Please try again.