Skip to content

Commit

Permalink
Add font size settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Jun 22, 2024
1 parent 1113e79 commit 59126bf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TextChatTranslator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
private func openSettings() {
let openSettings = OpenSettings()
openSettings.openSettings()
NSApp.activate()
NSApp.activate(ignoringOtherApps: true)
}
#endif

Expand Down
21 changes: 21 additions & 0 deletions TextChatTranslator/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"sourceLanguage" : "en",
"strings" : {
"%lld pt" : {

},
"Background Color:" : {

},
"Font Size:" : {

},
"Install Translation" : {

},
"Quit Text Chat Translator" : {
"localizations" : {
"ja" : {
Expand All @@ -13,6 +25,9 @@
},
"Settings…" : {

},
"Source Language:" : {

},
"Start Translation" : {
"localizations" : {
Expand All @@ -33,6 +48,12 @@
}
}
}
},
"Target Language:" : {

},
"Text Color:" : {

}
},
"version" : "1.0"
Expand Down
9 changes: 6 additions & 3 deletions TextChatTranslator/OverlayWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ fileprivate class OverlayContentView: NSView {

@AppStorage("backgroundColor") private var backgroundColor = Color.white
@AppStorage("textColor") private var textColor = Color.black
@AppStorage("fontSize" )private var fontSize = 16

private let textLabel = NSTextField(wrappingLabelWithString: "")
private let defaultFont: NSFont = .systemFont(ofSize: 16)
var leadingMargin: CGFloat = 0 {
didSet {
leadingConstraint?.constant = leadingMargin
}
}
private var leadingConstraint: NSLayoutConstraint?
private var preferredFont: NSFont {
NSFont.systemFont(ofSize: CGFloat(fontSize))
}

override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
Expand All @@ -117,7 +120,7 @@ fileprivate class OverlayContentView: NSView {
textLabel.translatesAutoresizingMaskIntoConstraints = true
containerView.addSubview(textLabel)

textLabel.font = defaultFont
textLabel.font = preferredFont
textLabel.textColor = NSColor(textColor)
textLabel.backgroundColor = .clear
textLabel.drawsBackground = false
Expand All @@ -137,7 +140,7 @@ fileprivate class OverlayContentView: NSView {
containerSize.width -= leadingMargin
containerSize.height = .greatestFiniteMagnitude

var font = defaultFont
var font = preferredFont
var fontSize = font.pointSize
var boundingRect: CGRect = .infinite

Expand Down
7 changes: 7 additions & 0 deletions TextChatTranslator/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SettingsView: View {
struct TranslationSettingsView: View {
@AppStorage("backgroundColor") private var backgroundColor = Color.white
@AppStorage("textColor" )private var textColor = Color.black
@AppStorage("fontSize" )private var fontSize = 16

@AppStorage("sourceLanguage") private var sourceLanguage = "en-Latn-US"
@AppStorage("targetLanguage") private var targetLanguage = "ja-Jpan-JP"
Expand All @@ -27,6 +28,12 @@ struct TranslationSettingsView: View {
Form {
ColorPicker("Background Color:", selection: $backgroundColor)
ColorPicker("Text Color:", selection: $textColor)
Picker("Font Size:", selection: $fontSize) {
ForEach([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 28, 30, 32, 34, 36, 40, 44], id: \.self) { (size) in
Text("\(size) pt")
.tag(size)
}
}

Divider()
.padding(.vertical)
Expand Down

0 comments on commit 59126bf

Please sign in to comment.