From 179fdf590cd26f00798678ff80abb37393fbd28b Mon Sep 17 00:00:00 2001 From: ARANR018 Date: Fri, 1 Oct 2021 18:08:42 -0400 Subject: [PATCH] add pad param to atrbutedTitle function to fix padding between icon and title in menubar --- SwiftBar/MenuBar/MenuBarItem.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SwiftBar/MenuBar/MenuBarItem.swift b/SwiftBar/MenuBar/MenuBarItem.swift index ce5dea2..887c41b 100644 --- a/SwiftBar/MenuBar/MenuBarItem.swift +++ b/SwiftBar/MenuBar/MenuBarItem.swift @@ -136,7 +136,7 @@ extension MenubarItem: NSMenuDelegate { params.params["color"] = "white" params.params["sfcolor"] = "white" if !AppShared.isReduceTransparencyEnabled { - barItem.button?.attributedTitle = atributedTitle(with: params).title + barItem.button?.attributedTitle = atributedTitle(with: params, pad: true).title } hotKeys.forEach { $0.isPaused = true } @@ -500,7 +500,7 @@ extension MenubarItem { barItem.button?.image = image barItem.button?.imagePosition = .imageLeft } - barItem.button?.attributedTitle = atributedTitle(with: params).title + barItem.button?.attributedTitle = atributedTitle(with: params, pad: true).title } func cycleThroughTitles() { @@ -511,7 +511,7 @@ extension MenubarItem { setMenuTitle(title: titleLines[currentTitleLineIndex]) } - func atributedTitle(with params: MenuLineParameters) -> (title: NSAttributedString, tooltip: String) { + func atributedTitle(with params: MenuLineParameters, pad: Bool = false) -> (title: NSAttributedString, tooltip: String) { var title = params.trim ? params.title.trimmingCharacters(in: .whitespaces) : params.title guard !title.isEmpty else { return (NSAttributedString(), "") } @@ -541,6 +541,11 @@ extension MenubarItem { if params.ansi { attributedTitle = title.colorizedWithANSIColor() } + + if attributedTitle.length > 0, pad { + attributedTitle.insert(NSAttributedString(string: " "), at: 0) + } + if !params.ansi { attributedTitle.addAttributes([.foregroundColor: color], range: NSRange(0 ..< attributedTitle.length))