Skip to content

Commit

Permalink
Make menu font monospaced using ImageRenderer
Browse files Browse the repository at this point in the history
#56
closes #851
  • Loading branch information
mobile-ar authored and nikitabobko committed Jan 12, 2025
1 parent 930222a commit 87634f8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Sources/AppBundle/MenuBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,32 @@ public func menuBar(viewModel: TrayMenuModel) -> some Scene {
terminateApp()
}.keyboardShortcut("Q", modifiers: .command)
} label: {
// .font(.system(.body, design: .monospaced)) doesn't work unfortunately :(
Text(viewModel.isEnabled ? viewModel.trayText : "⏸️")
if viewModel.isEnabled {
MonospacedText(viewModel.trayText)
} else {
MonospacedText("⏸️")

This comment has been minimized.

Copy link
@mobile-ar

mobile-ar Jan 15, 2025

Author Contributor

I think you don't need to use MonospacedText here with the pause emoji, you could just use plain Text.

This comment has been minimized.

Copy link
@nikitabobko

nikitabobko Jan 15, 2025

Owner

MonospacedText("⏸️") and Text("⏸️") look slightly different. I wanted the pause emoji and the normal workspace status to look the same

}
}
}

struct MonospacedText: View {
@Environment(\.colorScheme) var colorScheme: ColorScheme
var text: String
init(_ text: String) { self.text = text }

var body: some View {
let renderer = ImageRenderer(
content: Text(text)
.font(.system(.largeTitle, design: .monospaced))
.foregroundStyle(colorScheme == .light ? Color.black : Color.white)
)
if let cgImage = renderer.cgImage {
// Using scale: 1 results in a blurry image for unknown reasons
Image(cgImage, scale: 2, label: Text(text))
} else {
// In case image can't be rendered fallback to plain text
Text(text)
}
}
}

Expand Down

0 comments on commit 87634f8

Please sign in to comment.