Center the Home activity strip

This commit is contained in:
Georg Bauer
2026-07-31 18:00:51 +02:00
parent de49db0910
commit 9c7cef3869
2 changed files with 8 additions and 3 deletions

View File

@@ -562,8 +562,11 @@ final class HeatmapView: UIView {
(calendar.dateComponents([.day], from: firstWeek, to: lastDate).day ?? 0) / 7 + 1
)
let monthGap: CGFloat = 4
let width = max(4, min(6, (bounds.width - 32) / weekCount - 1))
let monthGaps = CGFloat(max(months.count - 1, 0)) * monthGap
let width = max(4, min(6, (bounds.width - 32 - monthGaps) / weekCount - 1))
let gap = width + 1
let graphWidth = (weekCount - 1) * gap + width + monthGaps
let graphOrigin = max(0, (bounds.width - graphWidth) / 2)
let labelAttributes: [NSAttributedString.Key: Any] = [
.font: UIFont.preferredFont(forTextStyle: .caption2),
.foregroundColor: UIColor.secondaryLabel,
@@ -572,7 +575,7 @@ final class HeatmapView: UIView {
let days = calendar.dateComponents([.day], from: firstWeek, to: month).day ?? 0
monthFormatter.string(from: month).draw(
at: CGPoint(
x: 16 + CGFloat(days / 7) * gap + CGFloat(index) * monthGap,
x: graphOrigin + CGFloat(days / 7) * gap + CGFloat(index) * monthGap,
y: 34
),
withAttributes: labelAttributes
@@ -595,7 +598,7 @@ final class HeatmapView: UIView {
colors[Int(min(cell.level, 4))].setFill()
UIBezierPath(
roundedRect: CGRect(
x: 16 + CGFloat(days / 7) * gap + CGFloat(monthIndex) * monthGap,
x: graphOrigin + CGFloat(days / 7) * gap + CGFloat(monthIndex) * monthGap,
y: 48 + CGFloat(calendar.component(.weekday, from: date) - 1) * gap,
width: width,
height: width