-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make menu font monospaced using ImageRenderer
- Loading branch information
1 parent
930222a
commit 87634f8
Showing
1 changed file
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nikitabobko
Owner
|
||
} | ||
} | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} | ||
|
||
|
I think you don't need to use
MonospacedText
here with the pause emoji, you could just use plainText
.