fix(ui): 缩小卡片并还原设计稿紧凑排布

This commit is contained in:
2026-11-15 17:14:42 +08:00
parent 3c1a2baace
commit d87aa3ccc5
29 changed files with 609 additions and 272 deletions
+2 -6
View File
@@ -5,15 +5,11 @@ struct FanSpeedIndicator: View {
let rpm: Double?
var body: some View {
HStack(spacing: 5) {
Image(systemName: "fanblades.fill")
.foregroundStyle(.secondary)
.frame(width: 14, height: 14).accessibilityHidden(true)
HStack(spacing: 4) {
title.foregroundStyle(.secondary)
Spacer(minLength: 2)
MetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM")
.monospacedDigit().fontWeight(.medium)
}
.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
}
}
+5 -3
View File
@@ -4,17 +4,19 @@ import SwiftUI
struct MetricProgressBar: View {
let value: Double
let color: Color
var cornerRadius: CGFloat? = nil
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
var body: some View {
GeometryReader { proxy in
let shape = RoundedRectangle(cornerRadius: cornerRadius ?? proxy.size.height / 2, style: .continuous)
ZStack(alignment: .leading) {
Capsule().fill(color.opacity(0.15))
Capsule().fill(color).frame(width: proxy.size.width * fraction)
shape.fill(color.opacity(0.15))
shape.fill(color).frame(width: proxy.size.width * fraction)
}
.frame(width: proxy.size.width, height: proxy.size.height)
.clipShape(Capsule())
.clipShape(shape)
.transaction { $0.animation = nil; $0.disablesAnimations = true }
}
}
+3 -2
View File
@@ -7,7 +7,7 @@ enum PanelStyle {
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 gap: CGFloat = 6
static let titleHeight: CGFloat = 20
}
@@ -38,6 +38,7 @@ struct CapacityBar: View {
let values: [Double]
let colors: [Color]
let total: Double
var height: CGFloat = 8
var body: some View {
GeometryReader { bounds in
@@ -49,7 +50,7 @@ struct CapacityBar: View {
}
.clipShape(Capsule())
}
.frame(height: 8)
.frame(height: height)
.accessibilityHidden(true)
}
}
+14 -14
View File
@@ -29,7 +29,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
.frame(width: bounds.size.width, height: ResourceCardMetrics.plotHeight)
VStack(alignment: .leading, spacing: ResourceCardMetrics.gap) {
header
HStack(alignment: .firstTextBaseline, spacing: 12) {
HStack(alignment: .firstTextBaseline, spacing: 6) {
MetricHeadline(value: value, compact: secondaryValue != nil, color: valueColor ?? .primary)
if let secondaryValue {
MetricHeadline(value: secondaryValue, compact: true, color: secondaryValueColor ?? .primary)
@@ -40,18 +40,18 @@ struct ResourceCard<Chart: View, Content: View>: View {
content()
Spacer(minLength: 0)
}
.font(PanelStyle.label)
.font(.system(size: 9))
.padding(ResourceCardMetrics.padding)
.padding(.bottom, ResourceCardMetrics.plotHeight - ResourceCardMetrics.padding)
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
}
.background(Color("PanelCard"))
.clipShape(.rect(cornerRadius: ResourceCardMetrics.radius))
.overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(0.07)))
.overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(colorScheme == .dark ? 0.06 : 0.025)))
.background {
RoundedRectangle(cornerRadius: ResourceCardMetrics.radius)
.fill(Color("PanelCard"))
.shadow(color: .black.opacity(colorScheme == .dark ? 0.16 : 0.06), radius: 6, x: 0, y: 2)
.shadow(color: .black.opacity(colorScheme == .dark ? 0.12 : 0.05), radius: 4, x: 0, y: 1)
}
}
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
@@ -77,19 +77,19 @@ struct ResourceCard<Chart: View, Content: View>: View {
} icon: {
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
}
.font(.system(size: 14, weight: .semibold)).fixedSize()
.font(.system(size: 11, weight: .semibold)).fixedSize()
Spacer(minLength: 4)
if let status {
Text(verbatim: status)
.font(.system(size: 11, weight: .medium))
.font(.system(size: 9, weight: .medium))
.foregroundStyle(statusWarning ? .red : .secondary)
.help(warningText ?? Text(verbatim: status))
.accessibilityLabel(warningText.map { Text("\(status) \($0)") } ?? Text(verbatim: status))
}
if let detail {
Text(verbatim: detail)
.font(.system(size: 10, weight: .medium)).foregroundStyle(detailColor ?? .secondary)
.padding(.horizontal, 6).frame(height: 18)
.font(.system(size: 8, weight: .medium)).foregroundStyle(detailColor ?? .secondary)
.padding(.horizontal, 5).frame(height: 14)
.background((detailColor ?? .primary).opacity(0.10), in: Capsule())
.lineLimit(1)
.help(Text(verbatim: detailHelp ?? detail))
@@ -115,20 +115,20 @@ private struct MetricHeadline: View {
}
var body: some View {
HStack(alignment: .firstTextBaseline, spacing: 3) {
HStack(alignment: .firstTextBaseline, spacing: 2) {
if let direction {
Image(systemName: direction == "↓" ? "arrow.down" : "arrow.up")
.font(.system(size: 16, weight: .medium))
.font(.system(size: 12, weight: .medium)).foregroundStyle(color)
}
Text(verbatim: parts.first.map(String.init) ?? value)
.font(.system(size: compact ? 23 : 36, weight: .semibold))
.font(.system(size: compact ? 16 : 28, weight: .semibold))
if parts.count > 1 {
Text(verbatim: String(parts[1]))
.font(.system(size: compact ? 11 : 14, weight: .medium))
.foregroundStyle(Color.secondary)
.font(.system(size: compact ? 9 : 12, weight: .medium))
.foregroundStyle(Color.primary.opacity(0.8))
}
}
.monospacedDigit().foregroundStyle(color)
.monospacedDigit().foregroundStyle(.primary)
.lineLimit(1).minimumScaleFactor(0.75)
.frame(maxWidth: .infinity, alignment: .leading)
.help(Text(verbatim: value))
+10 -9
View File
@@ -1,13 +1,14 @@
import CoreGraphics
/// Shared geometry for resource foregrounds, background plots and panel budgets.
/// Compact native geometry: card width and height are 2/3 of the first implementation.
nonisolated enum ResourceCardMetrics {
static let minimumHeight: CGFloat = 264
static let padding: CGFloat = 16
static let radius: CGFloat = 20
static let plotHeight: CGFloat = 72
static let titleHeight: CGFloat = 20
static let headlineHeight: CGFloat = 44
static let gap: CGFloat = 6
static let tooltipMinimumY: CGFloat = 96
static let preferredWidth: CGFloat = 308 * 2 / 3
static let minimumHeight: CGFloat = 176
static let padding: CGFloat = 10
static let radius: CGFloat = 16
static let plotHeight: CGFloat = 48
static let titleHeight: CGFloat = 14
static let headlineHeight: CGFloat = 34
static let gap: CGFloat = 4
static let tooltipMinimumY: CGFloat = 68
}