From c91843992b7390abc894fd26524db4ab17e809c1 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:52:22 -0400 Subject: [PATCH] Internalize bufferCalculatedWidth to Status Container View. --- .../Menu Bar/StatusContainerView.swift | 28 ++----------------- .../Menu Bar/StatusItemHandler.swift | 25 ++++++++++++++++- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Clocker/Preferences/Menu Bar/StatusContainerView.swift b/Clocker/Preferences/Menu Bar/StatusContainerView.swift index b4fee8b..1f2a66a 100644 --- a/Clocker/Preferences/Menu Bar/StatusContainerView.swift +++ b/Clocker/Preferences/Menu Bar/StatusContainerView.swift @@ -4,28 +4,6 @@ import Cocoa import CoreLoggerKit import CoreModelKit -func bufferCalculatedWidth() -> Int { - var totalWidth = 55 - - if DataStore.shared().shouldShowDayInMenubar() { - totalWidth += 12 - } - - if DataStore.shared().isBufferRequiredForTwelveHourFormats() { - totalWidth += 20 - } - - if DataStore.shared().shouldShowDateInMenubar() { - totalWidth += 20 - } - - if DataStore.shared().shouldDisplay(.showMeetingInMenubar) { - totalWidth += 100 - } - - return totalWidth -} - func compactWidth(for timezone: TimezoneData) -> Int { var totalWidth = 55 let timeFormat = timezone.timezoneFormat(DataStore.shared().timezoneFormat()) @@ -78,7 +56,7 @@ class StatusContainerView: NSView { layer?.backgroundColor = NSColor.clear.cgColor } - init(with timezones: [Data], showUpcomingEventView: Bool) { + init(with timezones: [Data], showUpcomingEventView: Bool, bufferContainerWidth: Int) { func addSubviews() { if showUpcomingEventView, let events = EventCenter.sharedCenter().eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: Date())], @@ -119,7 +97,7 @@ class StatusContainerView: NSView { return result + max(calculatedTitleSize.width, calculatedSubtitleSize.width) + bufferWidth + secondsBuffer } - return result + CGFloat(bufferCalculatedWidth()) + return result + CGFloat(bufferContainerWidth) } if showUpcomingEventView { @@ -127,7 +105,7 @@ class StatusContainerView: NSView { } let calculatedWidth = min(compressedWidth, - CGFloat(timezones.count * bufferCalculatedWidth())) + CGFloat(timezones.count * bufferContainerWidth)) return calculatedWidth } diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index e2d3cc8..6f64539 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -148,7 +148,8 @@ class StatusItemHandler: NSObject { } statusContainerView = StatusContainerView(with: menubarTimezones, - showUpcomingEventView: upcomingEventView) + showUpcomingEventView: upcomingEventView, + bufferContainerWidth: bufferCalculatedWidth()) statusItem.view = statusContainerView statusItem.view?.window?.backgroundColor = NSColor.clear } @@ -386,4 +387,26 @@ class StatusItemHandler: NSObject { }) return upcomingEventView } + + private func bufferCalculatedWidth() -> Int { + var totalWidth = 55 + + if store.shouldShowDayInMenubar() { + totalWidth += 12 + } + + if store.isBufferRequiredForTwelveHourFormats() { + totalWidth += 20 + } + + if store.shouldShowDateInMenubar() { + totalWidth += 20 + } + + if store.shouldDisplay(.showMeetingInMenubar) { + totalWidth += 100 + } + + return totalWidth + } }