feat(menubar): 实现紧凑独立双列与按内容定高

This commit is contained in:
2026-11-08 18:47:01 +08:00
parent 8821089872
commit 8d3891966a
22 changed files with 259 additions and 128 deletions
+28 -15
View File
@@ -14,26 +14,39 @@ import CoreGraphics
precondition(visible.insetBy(dx: 16, dy: 16).contains(centered))
}
}
let compact = PanelLayout.cardHeights(coreRows: 2, fanCount: 2)
precondition(PanelLayout.cardColumns(columns: 2) == [[.cpu, .gpu, .memory], [.battery, .storage, .network]])
precondition(PanelLayout.cardColumns(columns: 1).first == PanelCard.allCases)
for width: CGFloat in [480, 559, 560, 600, 640, 960] {
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)
let rows = PanelLayout.rowHeights(columns: columns, coreRows: 3, fanCount: 6)
let requirements: [CGFloat] = [246, 204, 256, 204, 260, 260]
for index in requirements.indices {
precondition(rows[index / columns] >= requirements[index])
}
precondition(rows.count == (6 + columns - 1) / columns)
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 600), rows: rows))
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), rows: rows))
let cards = PanelLayout.cardColumns(columns: columns).flatMap { $0 }
precondition(cards.count == 6 && Set(cards) == Set(PanelCard.allCases))
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 500), heights: compact))
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), heights: compact))
}
precondition(PanelLayout.rowHeights(columns: 2, coreRows: 2, fanCount: 0) == [220, 204, 260])
precondition(PanelLayout.columns(width: 960) == 2 && PanelLayout.columns(width: 559) == 1 && PanelLayout.columns(width: 640) == 2)
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), rows: [220, 204, 260]))
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 800), rows: [220, 204, 260]),
"Moving the interval to the footer must let the standard two-column overview fit")
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 760), rows: [220, 204, 260]))
precondition(PanelLayout.columnHeights(columns: 2, heights: compact) == [612, 564])
precondition(PanelLayout.preferredHeight(width: 640, heights: compact) == 706)
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 706), heights: compact))
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, height: 680), heights: compact))
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 480, height: 800), heights: compact))
precondition(PanelLayout.columns(width: 640) == 2 && PanelLayout.columns(width: 559) == 1)
let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2)
precondition(tallerCPU[.cpu]! > compact[.cpu]! && tallerCPU[.battery] == compact[.battery],
"A taller CPU card must not stretch the opposite battery card")
let moreFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 6)
precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage])
let noFans = PanelLayout.cardHeights(coreRows: 2, fanCount: 0)
precondition(noFans[.gpu] == 124 && PanelLayout.preferredHeight(width: 640, heights: noFans) < 706)
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: 640, heights: manyCores) == 800)
precondition(PanelLayout.needsResourceScroll(size: CGSize(width: 640, 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
let id = ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0)
let path: String? = index == 42 ? "/test/needle" : nil
@@ -61,6 +74,6 @@ import CoreGraphics
}
let pidSorted = ProcessTableProjection.rows(input, query: "", sorting: [ProcessSort(key: .pid)], order: [])
precondition(pidSorted.first?.id.pid == 2000)
print("PASS: physical-row heights, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results")
print("PASS: independent columns, hardware-driven heights, scroll and screen limits, column breakpoints, width conservation, resource scrolling, visible-frame bounds/chrome/negative origins, 2000-row CPU/footprint projection, frozen order, path search and empty results")
}
}