75 lines
2.8 KiB
Swift
75 lines
2.8 KiB
Swift
import SwiftUI
|
||
|
||
/// Die Keilhöhen als Draufsicht auf das Fahrzeug.
|
||
///
|
||
/// Vier Zahlen an vier Rädern, statt zweier Angaben „rechts" und „vorne", die
|
||
/// sich nicht getrennt ausführen lassen. Oben ist vorne; links im Bild ist
|
||
/// links am Fahrzeug, aus Sicht des Fahrers.
|
||
///
|
||
/// Das höchststehende Rad bekommt nichts – es bleibt liegen, die anderen
|
||
/// werden auf seine Höhe gebracht.
|
||
struct WheelLiftPlan: View {
|
||
let lift: LevelingLift
|
||
/// Für die Uhr: kleinere Schrift, engerer Aufbau.
|
||
var isCompact = false
|
||
|
||
var body: some View {
|
||
VStack(spacing: isCompact ? 2 : 6) {
|
||
Text("vorne")
|
||
.font(labelFont)
|
||
.foregroundStyle(.secondary)
|
||
|
||
HStack(spacing: isCompact ? 6 : 12) {
|
||
VStack(spacing: isCompact ? 6 : 14) {
|
||
badge(.frontLeft)
|
||
badge(.rearLeft)
|
||
}
|
||
body_
|
||
VStack(spacing: isCompact ? 6 : 14) {
|
||
badge(.frontRight)
|
||
badge(.rearRight)
|
||
}
|
||
}
|
||
|
||
Text("hinten")
|
||
.font(labelFont)
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
.accessibilityElement(children: .combine)
|
||
.accessibilityLabel(accessibilityText)
|
||
}
|
||
|
||
/// Der Umriss dazwischen macht aus vier Zahlen ein Fahrzeug.
|
||
private var body_: some View {
|
||
RoundedRectangle(cornerRadius: isCompact ? 4 : 8)
|
||
.strokeBorder(Color.secondary.opacity(0.4), lineWidth: 1)
|
||
.frame(width: isCompact ? 26 : 48, height: isCompact ? 44 : 84)
|
||
}
|
||
|
||
private func badge(_ wheel: LevelingLift.Wheel) -> some View {
|
||
let value = lift.centimetres(wheel)
|
||
let needed = value >= 1
|
||
return Text(needed ? String(format: "%.0f", value) : "–")
|
||
.font(valueFont)
|
||
.monospacedDigit()
|
||
.foregroundStyle(needed ? .primary : .secondary)
|
||
.frame(width: isCompact ? 26 : 42, height: isCompact ? 20 : 30)
|
||
.background(needed ? Color.orange.opacity(0.25) : Color.secondary.opacity(0.12),
|
||
in: .rect(cornerRadius: isCompact ? 4 : 6))
|
||
}
|
||
|
||
private var labelFont: Font { isCompact ? .system(size: 9) : .caption2 }
|
||
private var valueFont: Font {
|
||
isCompact ? .system(size: 12, weight: .semibold) : .callout.weight(.semibold)
|
||
}
|
||
|
||
private var accessibilityText: String {
|
||
let parts = LevelingLift.Wheel.allCases.compactMap { wheel -> String? in
|
||
let value = lift.centimetres(wheel)
|
||
guard value >= 1 else { return nil }
|
||
return String(format: "%@ %.0f Zentimeter", wheel.text, value)
|
||
}
|
||
return parts.isEmpty ? "Keine Keile nötig" : "Unterlegen: " + parts.joined(separator: ", ")
|
||
}
|
||
}
|