Skip to content

Commit

Permalink
added basic text sizing ability
Browse files Browse the repository at this point in the history
  • Loading branch information
mralexgray committed Sep 7, 2015
1 parent a55a9a9 commit 8903f2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions App/BitBar/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,23 @@ - (NSMenuItem *) buildMenuItemWithParams:(NSDictionary *)params {
item.representedObject = params;
[item setTarget:self];
}
if ([params objectForKey:@"color"] != nil) {
if (params[@"size"] || params[@"color"])
item.attributedTitle = [self attributedTitleWithParams:params];
}

return item;
}

- (NSAttributedString *) attributedTitleWithParams:(NSDictionary *)params {
NSString * title = [params objectForKey:@"title"];
NSFont * font = [NSFont menuFontOfSize:14.0];
NSFont * font = [NSFont menuFontOfSize:params[@"size"] ? [params[@"size"] floatValue] : 14];

NSMutableAttributedString * attributedTitle = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: font}];
if ([params objectForKey:@"color"] != nil) {
if (params[@"color"]) {
NSColor * fgColor = [NSColor colorWithWebColorString:[params objectForKey:@"color"]];
if (fgColor != nil) {
if (fgColor)
[attributedTitle addAttribute:NSForegroundColorAttributeName value:fgColor range:NSMakeRange(0, title.length)];
}
}

return attributedTitle;
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ensure the plugin is executable by running `chmod +x plugin.sh`.
* Your lines might contain `|` to separate the title from other parameters, such as...
* `href=..` to make the dropdown items clickable
* `color=..` to change their text color. eg. `color=red` or `color=#ff0000`
* `size=..` to change their text size. eg. `size=12`
* `bash=..` to make the dropdown items open terminal with your script e.g. `bash=/Users/user/BitBar_Plugins/scripts/nginx.restart.sh`
* `param1=..` if sh script need params
* `param2=..` if sh script need params
Expand Down

0 comments on commit 8903f2d

Please sign in to comment.