fix(ui): 缩小卡片并还原设计稿紧凑排布
This commit is contained in:
@@ -9,15 +9,15 @@ import SwiftUI
|
||||
if let first = rows.first, let last = rows.last {
|
||||
precondition(last > 0 && first - last <= 1)
|
||||
let columns = rows.max()!
|
||||
let cellWidth = (width - Double(columns - 1) * 6) / Double(columns)
|
||||
precondition(cellWidth >= 16, "Core text must fit a readable cell instead of being forced into three rows")
|
||||
let cellWidth = (width - Double(columns - 1) * 3) / Double(columns)
|
||||
precondition(cellWidth >= 8, "Each real core needs its own visible meter cell")
|
||||
}
|
||||
}
|
||||
}
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 430) == [9, 9])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 280) == [9, 9])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 32, width: 430) == [16, 16])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 48, width: 430) == [16, 16, 16])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 430) == [18])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 280) == [18])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 32, width: 430) == [32])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 48, width: 430) == [24, 24])
|
||||
for count in [0, 1, 4, 8, 14, 18, 24, 32, 48, 128] {
|
||||
let kinds = Dictionary(uniqueKeysWithValues: (0..<count).map { ($0, $0 < count / 3 ? CPUCoreTopology.Kind.efficiency : .performance) })
|
||||
let groups = CPUCoreGrid.groups(count: count, kinds: kinds)
|
||||
@@ -25,7 +25,7 @@ import SwiftUI
|
||||
for width in [120.0, 280.0, 380.0, 800.0] {
|
||||
let widths = CPUCoreGrid.groupWidths(groups: groups, width: width)
|
||||
precondition(widths.allSatisfy { $0 >= 0 && $0.isFinite })
|
||||
precondition(widths.reduce(0, +) <= width + 0.001)
|
||||
precondition(widths.allSatisfy { $0 <= width })
|
||||
for (group, groupWidth) in zip(groups, widths) {
|
||||
let rows = CPUCoreGridLayout.rowCounts(count: group.count, width: groupWidth)
|
||||
precondition(rows.reduce(0, +) == group.count)
|
||||
@@ -36,6 +36,6 @@ import SwiftUI
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 128, width: width).reduce(0, +) == 128)
|
||||
}
|
||||
precondition(CPUCoreGrid.groups(count: 3, kinds: [0: .efficiency]).count == 2)
|
||||
print("PASS: balanced core rows at multiple widths and counts")
|
||||
print("PASS: compact per-core meters with intact identities and bounded wrapping at multiple widths/counts")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import Foundation
|
||||
compressed: 2 << 30, swapUsed: 0, pressure: pressure, cached: 12 << 30)
|
||||
let header = MemoryHeaderInfo(memory: memory, locale: locale, bundle: bundle)
|
||||
precondition(header.title == title)
|
||||
precondition(header.badgeTitle == localized("memory.pressurePrefix") + title)
|
||||
precondition(header.help.components(separatedBy: "\n") == [
|
||||
"\(localized("memory.pressure")): \(title)",
|
||||
"\(localized("memory.cached")): 12.0 GiB",
|
||||
@@ -24,6 +25,7 @@ import Foundation
|
||||
swapUsed: nil, pressure: pressure)
|
||||
let header = MemoryHeaderInfo(memory: unknown, locale: locale, bundle: bundle)
|
||||
precondition(header.title == "--")
|
||||
precondition(header.badgeTitle == "--")
|
||||
precondition(header.help.components(separatedBy: "\n").allSatisfy { $0.hasSuffix(": --") })
|
||||
}
|
||||
let absent = MemoryHeaderInfo(memory: nil, locale: locale, bundle: bundle)
|
||||
|
||||
@@ -3,7 +3,7 @@ import CoreGraphics
|
||||
|
||||
@main struct PanelLayoutChecks {
|
||||
static func main() {
|
||||
precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)) == CGSize(width: 960, height: 630))
|
||||
precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)) == CGSize(width: 648, height: 448))
|
||||
for visible in [CGRect(x: 0, y: 67, width: 1512, height: 882), CGRect(x: -1440, y: -200, width: 1440, height: 800), CGRect(x: 0, y: 24, width: 800, height: 600)] {
|
||||
let content = PanelLayout.contentSize(visible: visible, chrome: CGSize(width: 4, height: 12))
|
||||
precondition(content.width + 4 <= visible.width - 32 && content.height + 12 <= visible.height - 32)
|
||||
@@ -18,48 +18,48 @@ import CoreGraphics
|
||||
precondition(PanelLayout.cardRows(columns: 3) == [[.cpu, .gpu, .memory], [.battery, .storage, .network]])
|
||||
precondition(PanelLayout.cardRows(columns: 2) == [[.cpu, .gpu], [.memory, .battery], [.storage, .network]])
|
||||
precondition(PanelLayout.cardRows(columns: 1) == PanelCard.allCases.map { [$0] })
|
||||
for width: CGFloat in [480, 559, 560, 600, 640, 899, 900, 960] {
|
||||
for width: CGFloat in [360, 429, 430, 559, 560, 619, 620, 648] {
|
||||
let size = CGSize(width: width, height: 820)
|
||||
let columns = PanelLayout.columns(width: width)
|
||||
let cardWidth = PanelLayout.cardWidth(size: size)
|
||||
precondition(abs(CGFloat(columns) * cardWidth + CGFloat(columns - 1) * 8 - (width - 20)) < 0.001)
|
||||
precondition(abs(CGFloat(columns) * cardWidth + CGFloat(columns - 1) * 6 - (width - 20)) < 0.001)
|
||||
let rows = PanelLayout.cardRows(columns: columns)
|
||||
precondition(rows.flatMap { $0 } == PanelCard.allCases)
|
||||
precondition(rows.allSatisfy { $0.count == columns })
|
||||
for (row, height) in zip(rows, PanelLayout.rowHeights(columns: columns, heights: compact)) {
|
||||
precondition(row.allSatisfy { (compact[$0] ?? 0) <= height }, "Every card must fit its aligned row")
|
||||
}
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 500), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 400), heights: compact))
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), heights: compact))
|
||||
}
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: compact) == [264, 264])
|
||||
precondition(PanelLayout.rowHeights(columns: 2, heights: compact) == [264, 264, 264])
|
||||
precondition(PanelLayout.cardWidth(size: CGSize(width: 960, height: 630)) == 308,
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: compact) == [176, 176])
|
||||
precondition(PanelLayout.rowHeights(columns: 2, heights: compact) == [176, 176, 176])
|
||||
precondition(PanelLayout.cardWidth(size: CGSize(width: 648, height: 448)) == ResourceCardMetrics.preferredWidth,
|
||||
"Three columns must retain readable card widths")
|
||||
precondition(PanelLayout.preferredHeight(width: 960, heights: compact) == 630)
|
||||
precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 800)
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 630), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 629), heights: compact))
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 902), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 901), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 480, height: 800), heights: compact))
|
||||
precondition(PanelLayout.columns(width: 960) == 3 && PanelLayout.columns(width: 900) == 3)
|
||||
precondition(PanelLayout.columns(width: 899) == 2 && PanelLayout.columns(width: 560) == 2 && PanelLayout.columns(width: 559) == 1)
|
||||
precondition(PanelLayout.preferredHeight(width: 648, heights: compact) == 448)
|
||||
precondition(PanelLayout.preferredHeight(width: 520, heights: compact) == 662)
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 648, height: 448), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 648, height: 447), heights: compact))
|
||||
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 520, height: 662), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 520, height: 661), heights: compact))
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 360, height: 800), heights: compact))
|
||||
precondition(PanelLayout.columns(width: 648) == 3 && PanelLayout.columns(width: 620) == 3)
|
||||
precondition(PanelLayout.columns(width: 619) == 2 && PanelLayout.columns(width: 430) == 2 && PanelLayout.columns(width: 429) == 1)
|
||||
let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2)
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: tallerCPU) == [368, 264],
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: tallerCPU) == [232, 176],
|
||||
"Extra CPU rows must grow the first grid row without changing the second")
|
||||
let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 10)
|
||||
precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage])
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: moreFans) == [344, 264])
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: moreFans) == [232, 176])
|
||||
let noFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 0)
|
||||
precondition(noFans[.gpu] == 264 && PanelLayout.rowHeights(columns: 3, heights: noFans) == [264, 264])
|
||||
precondition(PanelLayout.preferredHeight(width: 960, heights: noFans) == 630,
|
||||
precondition(noFans[.gpu] == 176 && PanelLayout.rowHeights(columns: 3, heights: noFans) == [176, 176])
|
||||
precondition(PanelLayout.preferredHeight(width: 648, heights: noFans) == 448,
|
||||
"A fanless GPU must keep row alignment with CPU and memory")
|
||||
precondition(PanelLayout.cardHeights(coreRows: 2, fanCount: nil) == compact,
|
||||
"Discovery placeholders must reserve the ordinary fan row")
|
||||
let manyCores = PanelLayout.cardHeights(coreRows: 30, fanCount: 10)
|
||||
precondition(PanelLayout.preferredHeight(width: 960, heights: manyCores) == 800)
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), heights: manyCores))
|
||||
precondition(PanelLayout.preferredHeight(width: 648, heights: manyCores) == 800)
|
||||
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 648, height: 800), heights: manyCores))
|
||||
let requested = PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900), preferredHeight: 732)
|
||||
precondition(requested.height == 732, "A hardware-driven height above the default must be preserved")
|
||||
let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user