feat(menubar): 实现紧凑独立双列与按内容定高
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Keep cores in two balanced rows when they fit, otherwise use at most three.
|
||||
/// Keep two balanced rows when possible; add rows to preserve readable core values.
|
||||
struct CPUCoreGrid: View {
|
||||
let values: [Double]
|
||||
let kinds: [Int: CPUCoreTopology.Kind]
|
||||
@@ -66,7 +66,7 @@ struct CPUCoreGrid: View {
|
||||
}
|
||||
}
|
||||
.frame(height: 15 + CGFloat(maxRows(groups: groups)) * 22 + CGFloat(max(0, maxRows(groups: groups) - 1)) * 4)
|
||||
.padding(.vertical, 4)
|
||||
.padding(.vertical, 1)
|
||||
}
|
||||
|
||||
// Match the content width so row reservation agrees with placement.
|
||||
@@ -102,10 +102,9 @@ struct CPUCoreGridLayout: Layout {
|
||||
static func rowCounts(count: Int, width: CGFloat) -> [Int] {
|
||||
guard count > 0 else { return [] }
|
||||
guard count > 1 else { return [1] }
|
||||
let twoColumns = (count + 1) / 2
|
||||
let availableForCells = width - CGFloat(twoColumns - 1) * columnSpacing
|
||||
let twoRowCellWidth = availableForCells / CGFloat(twoColumns)
|
||||
let rows = count > 2 && twoRowCellWidth < minimumTwoRowCellWidth ? 3 : 2
|
||||
let usableWidth = width.isFinite ? max(0, width) : 0
|
||||
let capacity = max(1, Int(min(CGFloat(count), (usableWidth + columnSpacing) / (minimumTwoRowCellWidth + columnSpacing))))
|
||||
let rows = max(2, (count + capacity - 1) / capacity)
|
||||
let quotient = count / rows, remainder = count % rows
|
||||
return (0..<rows).map { quotient + ($0 < remainder ? 1 : 0) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user