Skip to content

Commit

Permalink
add pad param to atrbutedTitle function to fix padding between icon a…
Browse files Browse the repository at this point in the history
…nd title in menubar
  • Loading branch information
ARANR018 authored and ARANR018 committed Oct 1, 2021
1 parent e74893c commit 179fdf5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions SwiftBar/MenuBar/MenuBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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() {
Expand All @@ -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(), "") }

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 179fdf5

Please sign in to comment.