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
+30 -8
View File
@@ -7,7 +7,7 @@ import SwiftUI
_ = NSApplication.shared
NSApp.setActivationPolicy(.accessory)
Task { @MainActor in
let window = NSWindow(contentRect: NSRect(x: 40, y: 40, width: 308, height: 264),
let window = NSWindow(contentRect: NSRect(x: 40, y: 40, width: 308 * 2 / 3, height: 176),
styleMask: [.borderless], backing: .buffered, defer: false)
window.isReleasedWhenClosed = false; window.level = .floating
let probe = DetailProbe()
@@ -16,9 +16,9 @@ import SwiftUI
for dark in [false, true] {
window.appearance = NSAppearance(named: dark ? .darkAqua : .aqua)
for language in ["zh-Hans", "zh-Hant", "en"] {
for width: CGFloat in [266, 308, 460] {
window.setContentSize(NSSize(width: width, height: 264))
host.rootView = AnyView(fixture(probe: probe, dualMetric: width == 308)
for width: CGFloat in [190, 308 * 2 / 3, 400] {
window.setContentSize(NSSize(width: width, height: 176))
host.rootView = AnyView(fixture(probe: probe, dualMetric: width < 300)
.environment(\.locale, Locale(identifier: language))
.environment(\.colorScheme, dark ? .dark : .light))
try? await Task.sleep(for: .milliseconds(80))
@@ -26,23 +26,45 @@ import SwiftUI
let plots = descendants(host).compactMap { $0 as? NativePanelCurve.PlotView }
precondition(plots.count == 1)
let plot = plots[0]
precondition(abs(plot.bounds.width - width) < 0.5 && plot.bounds.height == 72,
precondition(abs(host.bounds.width - width) < 1, "AppKit may round fractional content sizes to a point")
precondition(abs(plot.bounds.width - host.bounds.width) < 0.5 && plot.bounds.height == 48,
"The background chart must occupy the full card width, without axes or plot insets")
let graph = topRect(plot, in: host)
precondition(abs(graph.maxY - host.bounds.height) < 0.5,
"The background chart must end at the card bottom")
let detail = topRect(probe.view!, in: host)
precondition(detail.maxY <= graph.minY + 0.5 && detail.width <= width - 32 + 0.5,
precondition(detail.maxY <= graph.minY + 0.5 && detail.width <= host.bounds.width - 20 + 0.5,
"Foreground details must stay above the graph, including narrow/localized cards")
precondition(plot.grid.isHidden && plot.input?.visibleSeriesCount == 1)
}
}
}
// Render the production memory distribution: real UInt64 capacities must form visible segments.
window.appearance = NSAppearance(named: .aqua)
let memory = MemoryMetrics(total: 48 << 30, used: 26 << 30, wired: 3 << 30,
compressed: 1 << 30, swapUsed: 0, pressure: 1)
host.rootView = AnyView(MemoryDetailsView(memory: memory)
.frame(width: 185, height: 44, alignment: .topLeading)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.environment(\.colorScheme, .light))
try? await Task.sleep(for: .milliseconds(120))
host.layoutSubtreeIfNeeded()
let bitmap = host.bitmapImageRepForCachingDisplay(in: host.bounds)!
host.cacheDisplay(in: host.bounds, to: bitmap)
var colored = 0
for y in 0..<bitmap.pixelsHigh {
for x in 0..<bitmap.pixelsWide {
guard let c = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB) else { continue }
let components = [c.redComponent, c.greenComponent, c.blueComponent]
if components.max()! - components.min()! > 0.2 && c.alphaComponent > 0.2 { colored += 1 }
}
}
precondition(colored > 200, "Memory classification capacities must produce a visible proportion bar")
host.rootView = AnyView(EmptyView())
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 resource card/plot geometry at 266/308/460pt, light/dark, three languages, foreground separation and unmount")
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, foreground separation, memory distribution pixels and unmount")
NSApp.terminate(nil)
}
NSApp.run()
@@ -56,7 +78,7 @@ import SwiftUI
PanelTrendChart(dates: dates, first: Array(repeating: 0.3, count: 60),
second: Array(repeating: 0.6, count: 60), color: .blue)
}) {
DetailMarker(probe: probe).frame(height: 84)
DetailMarker(probe: probe).frame(height: 40)
}
}