108 lines
3.6 KiB
Swift
108 lines
3.6 KiB
Swift
import SwiftUI
|
|
|
|
/// Shared roles for the compact monitoring panel. Micro charts keep their own 8pt role.
|
|
enum PanelStyle {
|
|
static let title = Font.system(size: 13, weight: .semibold)
|
|
static let section = Font.system(size: 11, weight: .semibold)
|
|
static let label = Font.system(size: 10)
|
|
static let value = Font.system(size: 10, weight: .medium)
|
|
static let legend = Font.system(size: 9)
|
|
static let padding: CGFloat = 10
|
|
static let gap: CGFloat = 8
|
|
static let titleHeight: CGFloat = 20
|
|
static let plotHeight: CGFloat = 58
|
|
}
|
|
|
|
struct CardSeparator: View {
|
|
var body: some View {
|
|
Rectangle().fill(.primary.opacity(0.08)).frame(height: 1)
|
|
.padding(.vertical, 4)
|
|
.accessibilityHidden(true)
|
|
}
|
|
}
|
|
|
|
struct CardField<Content: View>: View {
|
|
let title: LocalizedStringKey
|
|
@ViewBuilder var content: () -> Content
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title)).frame(height: 14)
|
|
content().font(PanelStyle.value).monospacedDigit().frame(height: 14)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
|
|
struct CardSurface: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
content.modifier(PanelCardBackground(radius: 10))
|
|
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(.primary.opacity(0.14)))
|
|
}
|
|
}
|
|
|
|
struct CardInset: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
content.padding(.horizontal, 8).padding(.vertical, 5)
|
|
.background(.primary.opacity(0.04), in: RoundedRectangle(cornerRadius: 6))
|
|
}
|
|
}
|
|
|
|
/// Segment widths are proportional to the supplied total, without minimum fills.
|
|
struct CapacityBar: View {
|
|
let values: [Double]
|
|
let colors: [Color]
|
|
let total: Double
|
|
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
|
|
|
var body: some View {
|
|
GeometryReader { bounds in
|
|
HStack(spacing: 0) {
|
|
ForEach(values.indices, id: \.self) { index in
|
|
Rectangle().fill(colors.isEmpty ? Color.clear : colors[index % colors.count])
|
|
.frame(width: bounds.size.width * min(1, max(0, values[index] / max(1, total))))
|
|
}
|
|
}
|
|
.clipShape(Capsule())
|
|
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
|
}
|
|
.frame(height: 8)
|
|
.accessibilityHidden(true)
|
|
}
|
|
}
|
|
|
|
struct CapacityField: View {
|
|
let title: LocalizedStringKey
|
|
let value: String
|
|
let color: Color
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack(spacing: 3) {
|
|
Circle().fill(color).frame(width: 4, height: 4)
|
|
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).help(Text(title))
|
|
}.frame(height: 14)
|
|
AnimatedMetricText(value: value).font(PanelStyle.value).frame(height: 14)
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
|
|
struct CardSectionHeader: View {
|
|
let title: LocalizedStringKey
|
|
let valueLabel: LocalizedStringKey
|
|
let value: String
|
|
let color: Color
|
|
|
|
var body: some View {
|
|
HStack {
|
|
Text(title).font(PanelStyle.section)
|
|
Spacer(minLength: 4)
|
|
Text(valueLabel).font(PanelStyle.label).foregroundStyle(.secondary)
|
|
AnimatedMetricText(value: value).font(PanelStyle.value).foregroundStyle(color)
|
|
}.frame(height: 16)
|
|
}
|
|
}
|