Adding new parameter: sfsize #230

This commit is contained in:
Alex Mazanov 2021-10-26 13:00:05 -04:00
parent aa182ad1c1
commit c7fbcd08b8
4 changed files with 9 additions and 3 deletions

View File

@ -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` |

View File

@ -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()

View File

@ -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"

View File

@ -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 {