SFImage should respect width and height #245

This commit is contained in:
Alex Mazanov 2021-11-19 09:54:21 +01:00
parent d7ab6c15cd
commit 19bac5613e
No known key found for this signature in database
GPG Key ID: FD35C3C7C1D34AB4
2 changed files with 13 additions and 8 deletions

View File

@ -137,20 +137,25 @@ struct MenuLineParameters {
if #available(OSX 11.0, *) {
if let sfString = params["sfimage"] {
let config = NSImage.SymbolConfiguration(scale: .large)
return NSImage(systemSymbolName: sfString, accessibilityDescription: nil)?.withSymbolConfiguration(config)
let image = NSImage(systemSymbolName: sfString, accessibilityDescription: nil)?.withSymbolConfiguration(config)
image?.isTemplate = true
return resizedImageIfRequested(image)
}
}
let image = NSImage.createImage(from: params["image"] ?? params["templateimage"], isTemplate: params["templateimage"] != nil)
if let widthStr = params["width"], let width = Float(widthStr),
let heightStr = params["height"], let height = Float(heightStr)
{
return image?.resizedCopy(w: CGFloat(width), h: CGFloat(height))
}
return image
return resizedImageIfRequested(image)
}
private func resizedImageIfRequested(_ image: NSImage?) -> NSImage? {
guard let widthStr = params["width"], let width = Float(widthStr),
let heightStr = params["height"], let height = Float(heightStr) else {
return image
}
return image?.resizedCopy(w: CGFloat(width), h: CGFloat(height))
}
var emojize: Bool {
params["emojize"] != "false"
}

View File

@ -24,7 +24,7 @@ extension NSImage {
guard let data = newImage.tiffRepresentation,
let result = NSImage(data: data)
else { return NSImage() }
result.isTemplate = isTemplate
return result
}