Archived
Text(style: .timer) renders 1:23:45 once more than an hour out. An accessoryCorner has room for three or four characters beside its curved label, and a circular gauge for about the same, so the live timer overlapped what it sat next to. Replaced with a compact value — "23m", "2h", "3d" — recomputed per timeline entry, which is why the timeline now carries a mark every minute for the first hour. Both corner kinds and the gauge also get lineLimit(1) and a minimum scale factor, so an unexpectedly wide value shrinks instead of colliding. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.0 KiB
Swift
57 lines
2.0 KiB
Swift
import SwiftUI
|
|
import WidgetKit
|
|
import CalendarrCore
|
|
|
|
// A corner holds **one** value plus the curved bezel label. A second inner line
|
|
// runs into the curved text — do not add one. `.widgetLabel` is what makes
|
|
// WidgetKit lay the text along the edge; there is no arc to draw by hand.
|
|
|
|
/// Value: live countdown. Label: time and title.
|
|
struct CornerCountdownComplicationView: View {
|
|
let entry: WatchComplicationEntry
|
|
|
|
var body: some View {
|
|
let next = WatchComplicationSupport.nextEvent(in: entry.snapshot, at: entry.date)
|
|
Group {
|
|
if let next {
|
|
Text(WatchComplicationSupport.compactCountdown(
|
|
to: WatchComplicationSupport.countdownTarget(next, at: entry.date),
|
|
at: entry.date,
|
|
language: entry.language))
|
|
.lineLimit(1)
|
|
.minimumScaleFactor(0.6)
|
|
.widgetAccentable()
|
|
} else {
|
|
Image(systemName: "calendar")
|
|
}
|
|
}
|
|
.widgetLabel {
|
|
Text(WatchComplicationSupport.cornerLabel(next, at: entry.date, language: entry.language))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Value: the appointment's clock time. Label: the title.
|
|
struct CornerTimeComplicationView: View {
|
|
let entry: WatchComplicationEntry
|
|
|
|
var body: some View {
|
|
let next = WatchComplicationSupport.nextEvent(in: entry.snapshot, at: entry.date)
|
|
Group {
|
|
if let next {
|
|
Text(next.isAllDay
|
|
? WatchL10n.t("watch.allday", entry.language)
|
|
: WatchComplicationSupport.time(next.start, language: entry.language))
|
|
.lineLimit(1)
|
|
.minimumScaleFactor(0.6)
|
|
.widgetAccentable()
|
|
} else {
|
|
Image(systemName: "calendar")
|
|
}
|
|
}
|
|
.widgetLabel {
|
|
Text(next?.title ?? WatchL10n.t("watch.no_events", entry.language))
|
|
}
|
|
}
|
|
}
|