Browse Source

Internalize bufferCalculatedWidth to Status Container View.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
c91843992b
  1. 28
      Clocker/Preferences/Menu Bar/StatusContainerView.swift
  2. 25
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

28
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
}

25
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
}
}

Loading…
Cancel
Save