fix(ui): 提升卡片文字对比度与辅助信息可读性

This commit is contained in:
2026-11-15 19:51:47 +08:00
parent 60c146f8b7
commit 9088f8a251
14 changed files with 179 additions and 79 deletions
+36 -2
View File
@@ -36,6 +36,27 @@ import SwiftUI
precondition(detail.minY >= 0 && detail.maxY <= host.bounds.height && detail.width <= host.bounds.width - 20 + 0.5,
"Foreground details must overlay the full-height graph within card bounds, including narrow/localized cards")
precondition(plot.grid.isHidden && plot.input?.visibleSeriesCount == 1)
let bitmap = host.bitmapImageRepForCachingDisplay(in: host.bounds)!
host.cacheDisplay(in: host.bounds, to: bitmap)
func sample(_ y: Double) -> [Double] {
let c = bitmap.colorAt(x: bitmap.pixelsWide / 2, y: Int(y * Double(bitmap.pixelsHigh) / 176))!.usingColorSpace(.deviceRGB)!
return [Double(c.redComponent), Double(c.greenComponent), Double(c.blueComponent)]
}
let base = sample(3)
let covered = zip(sample(80), base).reduce(0.0) { $0 + abs($1.0 - $1.1) }
let open = zip(sample(150), base).reduce(0.0) { $0 + abs($1.0 - $1.1) }
precondition(open > 0.02 && covered < open * 0.35,
"Only the foreground area should suppress chart color; the bottom Spacer must remain uncovered: \(covered), \(open)")
for kind in 0...1 {
host.rootView = AnyView(detailsFixture(kind: kind, probe: probe)
.environment(\.locale, Locale(identifier: language))
.environment(\.colorScheme, dark ? .dark : .light))
try? await Task.sleep(for: .milliseconds(60)); host.layoutSubtreeIfNeeded()
let details = topRect(probe.view!, in: host)
precondition(details.maxY <= host.bounds.height - 10 + 0.5 && details.width <= host.bounds.width - 20 + 0.5,
"Larger production details must fit the unchanged card: \(kind), \(language), \(width), \(details)")
}
}
}
}
@@ -43,7 +64,7 @@ import SwiftUI
try? await Task.sleep(for: .milliseconds(100))
precondition(descendants(host).allSatisfy { !($0 is NativePanelCurve.PlotView) })
window.orderOut(nil); window.contentView = nil; window.close()
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, unmount")
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart overlay, foreground-only color shielding, larger localized memory/storage detail bounds, unmount")
NSApp.terminate(nil)
}
NSApp.run()
@@ -54,13 +75,26 @@ import SwiftUI
return ResourceCard(title: "metric.network", symbol: "network", color: .blue,
value: dualMetric ? "↓ 999.9 TB/s" : "99%", secondaryValue: dualMetric ? "↑ 999.9 TB/s" : nil,
chart: {
PanelTrendChart(dates: dates, first: Array(repeating: 0.3, count: 60),
PanelTrendChart(dates: dates, first: Array(repeating: 0.8, count: 60),
second: Array(repeating: 0.6, count: 60), color: .blue)
}) {
DetailMarker(probe: probe).frame(height: 40)
}
}
@MainActor private static func detailsFixture(kind: Int, probe: DetailProbe) -> some View {
let memory = MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30, compressed: 1 << 30,
swapUsed: 0, pressure: 1)
let details = kind == 0 ? AnyView(MemoryDetailsView(memory: memory))
: AnyView(StorageDetailsView(disk: .init(total: 1_000_000_000_000, available: 999_000_000_000),
health: .init(remainingLife: 0.98, powerOnHours: 99999),
io: .init(read: 999_900_000_000, written: 999_900_000_000)))
return ResourceCard(title: kind == 0 ? "metric.memory" : "metric.disk", symbol: "memorychip", color: .blue,
value: "26.0 / 48 GiB", chart: { Color.clear }) {
details.background(DetailMarker(probe: probe).allowsHitTesting(false))
}
}
@MainActor private static func descendants(_ view: NSView) -> [NSView] {
[view] + view.subviews.flatMap(descendants)
}