From 8903f2dca629d562c19271225f9da0ae2077cba4 Mon Sep 17 00:00:00 2001 From: Alex Gray Date: Mon, 7 Sep 2015 17:54:47 -0400 Subject: [PATCH] added basic text sizing ability --- App/BitBar/Plugin.m | 13 +++++++------ README.md | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/App/BitBar/Plugin.m b/App/BitBar/Plugin.m index a59ec6451..272a6e0df 100644 --- a/App/BitBar/Plugin.m +++ b/App/BitBar/Plugin.m @@ -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; } diff --git a/README.md b/README.md index 92308237e..9dd6a8dd8 100644 --- a/README.md +++ b/README.md @@ -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