fixed iOS widget layout
This commit is contained in:
@@ -39,8 +39,11 @@ func realMinutesToVirtual(_ realMin: Int, periods: [WidgetPeriod]) -> CGFloat {
|
||||
return 0
|
||||
}
|
||||
|
||||
let BLOCK_SHOW_ROOM_MIN: CGFloat = 18
|
||||
let BLOCK_SHOW_TEACHER_SEPARATE_MIN: CGFloat = 30
|
||||
// Below these tile heights the secondary stack collapses progressively:
|
||||
// shorter than ROOM_MIN drops everything, between ROOM_MIN and
|
||||
// TEACHER_SEPARATE_MIN keeps the room but drops the teacher.
|
||||
let BLOCK_SHOW_ROOM_MIN: CGFloat = 13
|
||||
let BLOCK_SHOW_TEACHER_SEPARATE_MIN: CGFloat = 20
|
||||
|
||||
let MIN_SUBJECT_FONT: CGFloat = 9
|
||||
let MAX_SUBJECT_FONT: CGFloat = 14
|
||||
@@ -70,7 +73,7 @@ struct TimetableDayView: View {
|
||||
|
||||
@ViewBuilder
|
||||
private func content(data: WidgetTimetableData) -> some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
header(data: data)
|
||||
if data.isHoliday {
|
||||
emptyState(text: data.holidayName ?? "Ferien")
|
||||
@@ -96,14 +99,18 @@ struct TimetableDayView: View {
|
||||
}
|
||||
|
||||
private func header(data: WidgetTimetableData) -> some View {
|
||||
HStack {
|
||||
HStack(spacing: 4) {
|
||||
Text(dayLabel(for: data.anchorDate))
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
.foregroundStyle(palette.textPrimary)
|
||||
Spacer()
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.7)
|
||||
Spacer(minLength: 4)
|
||||
Text("Stand: \(freshnessLabel(for: data.fetchedAt))")
|
||||
.font(.system(size: 10))
|
||||
.font(.system(size: 9))
|
||||
.foregroundStyle(palette.textSecondary)
|
||||
.lineLimit(1)
|
||||
.minimumScaleFactor(0.7)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +219,14 @@ struct TimeGridView: View {
|
||||
}
|
||||
|
||||
private var gridLines: some View {
|
||||
// `.frame(height: totalHeight, alignment: .top)` — without the
|
||||
// explicit `.top`, SwiftUI's frame modifier defaults to `.center`.
|
||||
// Every Rectangle here has layout-y=0 (the `.offset()`s shift the
|
||||
// rendered position only, not layout), so the inner ZStack's
|
||||
// natural height is just 1pt; a 1pt ZStack centred in a 300pt
|
||||
// frame anchors at the middle, and every line then renders
|
||||
// relative to that midpoint — the grid visually starts halfway
|
||||
// down the column and the later periods clip past the bottom.
|
||||
ZStack(alignment: .top) {
|
||||
ForEach(periodBoundaries(periods), id: \.self) { virtualMin in
|
||||
Rectangle()
|
||||
@@ -220,10 +235,11 @@ struct TimeGridView: View {
|
||||
.offset(y: CGFloat(virtualMin) * hourHeight / 60.0)
|
||||
}
|
||||
}
|
||||
.frame(height: totalHeight)
|
||||
.frame(height: totalHeight, alignment: .top)
|
||||
}
|
||||
|
||||
private var breakBlocks: some View {
|
||||
// Same `.center`-vs-`.top` bug as gridLines — see comment above.
|
||||
ZStack(alignment: .top) {
|
||||
ForEach(0..<max(0, periods.count - 1), id: \.self) { i in
|
||||
let curr = periods[i]
|
||||
@@ -238,7 +254,7 @@ struct TimeGridView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: totalHeight)
|
||||
.frame(height: totalHeight, alignment: .top)
|
||||
}
|
||||
|
||||
private func formatHm(_ minutes: Int) -> String {
|
||||
@@ -357,8 +373,12 @@ struct TimeGridView: View {
|
||||
}
|
||||
}
|
||||
switch lesson.status {
|
||||
case .regular, .past: return Color(red: 153/255.0, green: 51/255.0, blue: 51/255.0)
|
||||
case .ongoing: return Color(red: 200/255.0, green: 51/255.0, blue: 51/255.0)
|
||||
// `.ongoing` deliberately collapses into the regular red — the
|
||||
// widget timeline only ticks every ~30min, so highlighting the
|
||||
// "current" lesson would be stale most of the day and misleads
|
||||
// more than it helps.
|
||||
case .regular, .past, .ongoing:
|
||||
return Color(red: 153/255.0, green: 51/255.0, blue: 51/255.0)
|
||||
case .cancelled: return .black
|
||||
case .irregular: return Color(red: 143/255.0, green: 25/255.0, blue: 179/255.0)
|
||||
case .teacherChanged: return Color(red: 41/255.0, green: 99/255.0, blue: 155/255.0)
|
||||
|
||||
Reference in New Issue
Block a user