Browse Source

Only init paragraph style once.

master
Abhishek Banthia 9 months ago
parent
commit
d079a7d0c7
  1. 12
      Clocker/Preferences/Menu Bar/StatusContainerView.swift
  2. 14
      Clocker/Preferences/Menu Bar/StatusItemView.swift

12
Clocker/Preferences/Menu Bar/StatusContainerView.swift

@ -57,6 +57,16 @@ protocol StatusItemViewConforming {
class StatusContainerView: NSView { class StatusContainerView: NSView {
private var previousX: Int = 0 private var previousX: Int = 0
private let store: DataStore 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() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
@ -167,7 +177,7 @@ class StatusContainerView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
] ]
let operation = TimezoneDataOperations(with: timezone, store: store) let operation = TimezoneDataOperations(with: timezone, store: store)

14
Clocker/Preferences/Menu Bar/StatusItemView.swift

@ -53,6 +53,16 @@ class StatusItemView: NSView {
private var operationsObject: TimezoneDataOperations { private var operationsObject: TimezoneDataOperations {
return TimezoneDataOperations(with: dataObject, store: DataStore.shared()) 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] { private var timeAttributes: [NSAttributedString.Key: AnyObject] {
let textColor = hasDarkAppearance ? NSColor.white : NSColor.black let textColor = hasDarkAppearance ? NSColor.white : NSColor.black
@ -61,7 +71,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultTimeParagraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
] ]
return attributes return attributes
} }
@ -73,7 +83,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10),
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
] ]
return textFontAttributes return textFontAttributes
} }

Loading…
Cancel
Save