|
|
@ -77,8 +77,9 @@ class StatusContainerView: NSView { |
|
|
|
if let timezoneObject = TimezoneData.customObject(from: timezone) { |
|
|
|
if let timezoneObject = TimezoneData.customObject(from: timezone) { |
|
|
|
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) |
|
|
|
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) |
|
|
|
let operationObject = TimezoneDataOperations(with: timezoneObject) |
|
|
|
let operationObject = TimezoneDataOperations(with: timezoneObject) |
|
|
|
let calculatedSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeAttributes) |
|
|
|
let calculatedSubtitleSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeAttributes) |
|
|
|
return result + calculatedSize.width + bufferWidth |
|
|
|
let calculatedTitleSize = compactModeTimeFont.size(operationObject.compactMenuTitle(), precalculatedWidth, attributes: timeAttributes) |
|
|
|
|
|
|
|
return result + max(calculatedTitleSize.width, calculatedSubtitleSize.width) + bufferWidth |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result + CGFloat(bufferCalculatedWidth()) |
|
|
|
return result + CGFloat(bufferCalculatedWidth()) |
|
|
@ -114,10 +115,11 @@ class StatusContainerView: NSView { |
|
|
|
|
|
|
|
|
|
|
|
private func bestWidth(for timezone: TimezoneData) -> Int { |
|
|
|
private func bestWidth(for timezone: TimezoneData) -> Int { |
|
|
|
let operation = TimezoneDataOperations(with: timezone) |
|
|
|
let operation = TimezoneDataOperations(with: timezone) |
|
|
|
|
|
|
|
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(), |
|
|
|
|
|
|
|
Double(compactWidth(for: timezone)), attributes: timeAttributes) |
|
|
|
|
|
|
|
let bestTitleSize = compactModeTimeFont.size(operation.compactMenuTitle(), Double(compactWidth(for: timezone)), attributes: timeAttributes) |
|
|
|
|
|
|
|
|
|
|
|
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(), Double(compactWidth(for: timezone)), attributes: timeAttributes) |
|
|
|
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth) |
|
|
|
|
|
|
|
|
|
|
|
return Int(bestSize.width + bufferWidth) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateTime() { |
|
|
|
func updateTime() { |
|
|
@ -126,16 +128,25 @@ class StatusContainerView: NSView { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// See if frame's width needs any adjustment |
|
|
|
// See if frame's width needs any adjustment |
|
|
|
|
|
|
|
adjustWidthIfNeccessary() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func adjustWidthIfNeccessary() { |
|
|
|
var newWidth: CGFloat = 0 |
|
|
|
var newWidth: CGFloat = 0 |
|
|
|
|
|
|
|
|
|
|
|
subviews.forEach { |
|
|
|
subviews.forEach { |
|
|
|
if let statusItem = $0 as? StatusItemView { |
|
|
|
if let statusItem = $0 as? StatusItemView, statusItem.isHidden == false { |
|
|
|
// Determine what's the best width required to display the current string. |
|
|
|
// Determine what's the best width required to display the current string. |
|
|
|
let newBestWidth = CGFloat(bestWidth(for: statusItem.dataObject)) |
|
|
|
let newBestWidth = CGFloat(bestWidth(for: statusItem.dataObject)) |
|
|
|
|
|
|
|
|
|
|
|
// Let's note if the current width is too small/correct |
|
|
|
// Let's note if the current width is too small/correct |
|
|
|
newWidth += statusItem.frame.size.width != newBestWidth ? newBestWidth : statusItem.frame.size.width |
|
|
|
newWidth += statusItem.frame.size.width != newBestWidth ? newBestWidth : statusItem.frame.size.width |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statusItem.frame = CGRect(x: statusItem.frame.origin.x, |
|
|
|
|
|
|
|
y: statusItem.frame.origin.y, |
|
|
|
|
|
|
|
width: newBestWidth, |
|
|
|
|
|
|
|
height: statusItem.frame.size.height) |
|
|
|
|
|
|
|
|
|
|
|
statusItem.updateTimeInMenubar() |
|
|
|
statusItem.updateTimeInMenubar() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|