From c7fbcd08b82fbb6f9424a748e2f1d8573954f86a Mon Sep 17 00:00:00 2001 From: Alex Mazanov Date: Tue, 26 Oct 2021 13:00:05 -0400 Subject: [PATCH] Adding new parameter: sfsize #230 --- README.md | 1 + SwiftBar/MenuBar/MenuBarItem.swift | 2 +- SwiftBar/MenuBar/MenuLineParameters.swift | 5 +++++ SwiftBar/Utility/String+SFSymbols.swift | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6f21a23..642c853 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ echo "Line 1 \\n Line2 | size=8" | `sfcolor` | CSS color or HEX, `light_color,dark_color` | Sets SF Symbol color. If only one color is provided, it is used for both light and dark appearance. | | `font` | macOS font name | Sets font name to use in item text | | `size` | Number | Sets item text size | +| `sfsize` | Number | Sets size for SF Symbol image embedded in text| | `length`| Number | Trims item text to a provided number of characters. The full title will be displayed in a tooltip. | | `trim` | True | Trims whitespace characters | | `ansi` | True | Enables support of ANSI color codes. **Conflicts with:** `symbolize` | diff --git a/SwiftBar/MenuBar/MenuBarItem.swift b/SwiftBar/MenuBar/MenuBarItem.swift index 887c41b..6a35cbe 100644 --- a/SwiftBar/MenuBar/MenuBarItem.swift +++ b/SwiftBar/MenuBar/MenuBarItem.swift @@ -536,7 +536,7 @@ extension MenubarItem { var attributedTitle = NSMutableAttributedString(string: title) if params.symbolize, !params.ansi { - attributedTitle = title.symbolize(font: font, colors: params.sfcolors) + attributedTitle = title.symbolize(font: font, colors: params.sfcolors, sfsize: params.sfsize) } if params.ansi { attributedTitle = title.colorizedWithANSIColor() diff --git a/SwiftBar/MenuBar/MenuLineParameters.swift b/SwiftBar/MenuBar/MenuLineParameters.swift index 97b3cae..1cde9fc 100644 --- a/SwiftBar/MenuBar/MenuLineParameters.swift +++ b/SwiftBar/MenuBar/MenuLineParameters.swift @@ -106,6 +106,11 @@ struct MenuLineParameters { guard let sizeStr = params["size"], let pSize = Int(sizeStr) else { return nil } return CGFloat(pSize) } + + var sfsize: CGFloat? { + guard let sizeStr = params["sfsize"], let pSize = Int(sizeStr) else { return nil } + return CGFloat(pSize) + } var dropdown: Bool { params["dropdown"] != "false" diff --git a/SwiftBar/Utility/String+SFSymbols.swift b/SwiftBar/Utility/String+SFSymbols.swift index 883f9ed..510363d 100644 --- a/SwiftBar/Utility/String+SFSymbols.swift +++ b/SwiftBar/Utility/String+SFSymbols.swift @@ -1,7 +1,7 @@ import Cocoa extension String { - func symbolize(font: NSFont, colors: [NSColor]) -> NSMutableAttributedString { + func symbolize(font: NSFont, colors: [NSColor], sfsize: CGFloat?) -> NSMutableAttributedString { if #available(OSX 11.0, *) { var colors: [NSColor] = colors let out = NSMutableAttributedString() @@ -13,7 +13,7 @@ extension String { out.append(NSAttributedString(string: word)) return } - let imageConfig = NSImage.SymbolConfiguration(pointSize: font.pointSize, weight: .regular) + let imageConfig = NSImage.SymbolConfiguration(pointSize: sfsize ?? font.pointSize, weight: .regular) if let image = NSImage(systemSymbolName: String(word.dropFirst().dropLast()), accessibilityDescription: nil)?.withSymbolConfiguration(imageConfig) { let tintColor = colors.first if colors.count > 1 {