Skip to content

Commit

Permalink
Only init paragraph style once.
Browse files Browse the repository at this point in the history
  • Loading branch information
n0shake committed Mar 31, 2024
1 parent 5e03282 commit d079a7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Clocker/Preferences/Menu Bar/StatusContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ protocol StatusItemViewConforming {
class StatusContainerView: NSView {
private var previousX: Int = 0
private let store: DataStore
private lazy var paragraphStyle: NSMutableParagraphStyle = {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
paragraphStyle.lineBreakMode = .byTruncatingTail
// Better readability for p,q,y,g in the status bar.
let userPreferredLanguage = Locale.preferredLanguages.first ?? "en-US"
let lineHeight = userPreferredLanguage.contains("en") ? 0.92 : 1
paragraphStyle.lineHeightMultiple = CGFloat(lineHeight)
return paragraphStyle
}()

override func awakeFromNib() {
super.awakeFromNib()
Expand Down Expand Up @@ -167,7 +177,7 @@ class StatusContainerView: NSView {
NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
]

let operation = TimezoneDataOperations(with: timezone, store: store)
Expand Down
14 changes: 12 additions & 2 deletions Clocker/Preferences/Menu Bar/StatusItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class StatusItemView: NSView {
private var operationsObject: TimezoneDataOperations {
return TimezoneDataOperations(with: dataObject, store: DataStore.shared())
}
private lazy var paragraphStyle: NSMutableParagraphStyle = {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
paragraphStyle.lineBreakMode = .byTruncatingTail
// Better readability for p,q,y,g in the status bar.
let userPreferredLanguage = Locale.preferredLanguages.first ?? "en-US"
let lineHeight = userPreferredLanguage.contains("en") ? 0.92 : 1
paragraphStyle.lineHeightMultiple = CGFloat(lineHeight)
return paragraphStyle
}()

private var timeAttributes: [NSAttributedString.Key: AnyObject] {
let textColor = hasDarkAppearance ? NSColor.white : NSColor.black
Expand All @@ -61,7 +71,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultTimeParagraphStyle,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
]
return attributes
}
Expand All @@ -73,7 +83,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10),
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
]
return textFontAttributes
}
Expand Down

1 comment on commit d079a7d

@n0shake
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.3% in default paragraph style creation.

Screenshot 2024-03-31 at 4 55 31 PM

Please sign in to comment.