Skip to content

Commit

Permalink
Fix day of week icon dropping last letter (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Nov 10, 2024
1 parent fbdc5b5 commit ecf8bfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.2;
MARKETING_VERSION = 1.14.3;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down Expand Up @@ -1515,7 +1515,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.14.2;
MARKETING_VERSION = 1.14.3;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down
30 changes: 19 additions & 11 deletions Calendr/MenuBar/StatusItemIconFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import AppKit
enum StatusItemIconFactory {

static func icon(size: CGFloat, style: StatusItemIconStyle, textScaling: Double, dateProvider: DateProviding) -> NSImage {
let headerHeight: CGFloat = 3.5
let headerHeight: CGFloat = 3 * textScaling
let borderWidth: CGFloat = 2
let radius: CGFloat = 2.5
let ratio: CGFloat = 1.15
let rect = CGRect(x: 0, y: 0, width: size * ratio, height: size)
let rect = CGRect(x: 0, y: 0, width: size + borderWidth, height: size)

let image = NSImage(size: rect.size, flipped: true) { _ in
let size = switch style {
case .calendar, .date:
rect.size
case .dayOfWeek:
rect.insetBy(dx: -2, dy: -1).size
}

let image = NSImage(size: size, flipped: true) { _ in
/// can be any opaque color, but red is good for debugging
let color = NSColor.red
color.setStroke()
Expand Down Expand Up @@ -89,7 +95,7 @@ enum StatusItemIconFactory {
let date = formatter.string(from: dateProvider.now)
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
let fontSize = 0.5 * rect.height * textScaling
let fontSize = 0.6 * rect.height
NSAttributedString(string: date, attributes: [
.font: NSFont.systemFont(ofSize: fontSize, weight: .medium),
.foregroundColor: NSColor.red,
Expand All @@ -105,29 +111,31 @@ enum StatusItemIconFactory {
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center

let headerFontSize = round(6.5 * textScaling)
let dateFontSize = round(7.5 * textScaling)
let fontSize = 0.6 * rect.height
let middleY = rect.height / 2 - fontSize / 2 + 1
let middleYSpread = fontSize / 2.5 + 1
let insetX = 2.5

run {
formatter.dateFormat = "E"
let date = formatter.string(from: dateProvider.now).uppercased().trimmingCharacters(in: ["."])
NSAttributedString(string: date, attributes: [
.font: NSFont.systemFont(ofSize: headerFontSize, weight: .bold),
.font: NSFont.systemFont(ofSize: fontSize, weight: .bold),
.foregroundColor: NSColor.red,
.paragraphStyle: paragraph
])
.draw(in: rect.offsetBy(dx: 0, dy: -2).insetBy(dx: -0.5, dy: 0))
.draw(in: rect.offsetBy(dx: insetX, dy: middleY - middleYSpread).insetBy(dx: -insetX, dy: 0))
}

run {
formatter.dateFormat = "d"
let date = formatter.string(from: dateProvider.now)
NSAttributedString(string: date, attributes: [
.font: NSFont.systemFont(ofSize: dateFontSize, weight: .medium),
.font: NSFont.systemFont(ofSize: fontSize, weight: .bold),
.foregroundColor: NSColor.red,
.paragraphStyle: paragraph
])
.draw(in: rect.offsetBy(dx: 0, dy: rect.height / 3))
.draw(in: rect.offsetBy(dx: insetX, dy: middleY + middleYSpread).insetBy(dx: 0, dy: -1))
}
}
}
2 changes: 1 addition & 1 deletion Calendr/MenuBar/StatusItemViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class StatusItemViewModel {
let padding: NSPoint = text.isEmpty ? .init(x: border, y: border) : .init(x: 4, y: 2)
let spacing: CGFloat = 4
var iconsWidth = icons.map(\.size.width).reduce(0) { $0 + $1 + spacing }
let height = max(icons.map(\.size.height).reduce(0, max), 15)
let height = icons.map(\.size.height).reduce(0, max)
if text.isEmpty {
iconsWidth -= spacing
}
Expand Down

0 comments on commit ecf8bfb

Please sign in to comment.