import SwiftUI /// Shared roles for auxiliary labels and native panel controls. enum PanelStyle { static let title = Font.system(size: 13, 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 = 6 static let titleHeight: CGFloat = 20 } struct CardField: View { let title: LocalizedStringKey @ViewBuilder var content: () -> Content var body: some View { VStack(alignment: .leading, spacing: 4) { Text(title).font(PanelStyle.label).foregroundStyle(.secondary).frame(height: 14) .help(Text(title)) 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: ResourceCardMetrics.radius)) .overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(0.06))) } } /// Segment widths are proportional to the supplied total, without minimum fills. struct CapacityBar: View { let values: [Double] let colors: [Color] let total: Double var height: CGFloat = 8 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()) } .frame(height: height) .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) }.frame(height: 14) MetricText(value: value).font(PanelStyle.value).frame(height: 14) } .frame(maxWidth: .infinity, alignment: .leading) .lineLimit(1) } }