feat(menubar): 拆分紧凑双页面板并按页采样
This commit is contained in:
@@ -42,11 +42,6 @@ struct CPUCoreGrid: View {
|
||||
let groups = Self.groups(count: values.count, kinds: kinds)
|
||||
GeometryReader { geometry in
|
||||
let widths = Self.groupWidths(groups: groups, width: geometry.size.width)
|
||||
let diameter = zip(groups, widths).map { indices, width in
|
||||
let columns = CPUCoreGridLayout.rowCounts(count: indices.count, width: width).max() ?? 1
|
||||
let spacing = min(CPUCoreGridLayout.columnSpacing, max(0, (width / CGFloat(columns) - 18) / 2))
|
||||
return max(0, (width - CGFloat(columns - 1) * spacing) / CGFloat(columns) - 4)
|
||||
}.min() ?? 20
|
||||
HStack(alignment: .top, spacing: 6) {
|
||||
ForEach(groups.indices, id: \.self) { group in
|
||||
if group > 0 {
|
||||
@@ -63,7 +58,7 @@ struct CPUCoreGrid: View {
|
||||
.lineLimit(1).minimumScaleFactor(0.6)
|
||||
CPUCoreGridLayout {
|
||||
ForEach(groups[group], id: \.self) { index in
|
||||
ring(index: index, maximumDiameter: min(20, diameter))
|
||||
core(index: index)
|
||||
}
|
||||
}
|
||||
}.frame(width: widths[group], alignment: .topLeading)
|
||||
@@ -82,20 +77,17 @@ struct CPUCoreGrid: View {
|
||||
return zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0
|
||||
}
|
||||
|
||||
private func ring(index: Int, maximumDiameter: CGFloat) -> some View {
|
||||
private func core(index: Int) -> some View {
|
||||
let kind = kinds[index]
|
||||
let value = values[index].isFinite ? min(1, max(0, values[index])) : 0
|
||||
return GeometryReader { proxy in
|
||||
let diameter = min(maximumDiameter, max(0, proxy.size.width - 4))
|
||||
ZStack {
|
||||
NativeMetricRing(value: value, color: color(kind), lineWidth: 2, trackOpacity: 0.16, inset: 1)
|
||||
Text(verbatim: "\(Int((value * 100).rounded()))")
|
||||
.font(.system(size: 8, weight: .medium)).lineLimit(1).minimumScaleFactor(0.4)
|
||||
}
|
||||
.frame(width: diameter, height: diameter)
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
return VStack(spacing: 3) {
|
||||
Text(verbatim: "\(Int((value * 100).rounded()))")
|
||||
.font(.system(size: 8, weight: .medium)).monospacedDigit().lineLimit(1)
|
||||
MetricProgressBar(value: value, color: color(kind)).frame(height: 3)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.help(Text("\(kind.map { label($0) } ?? Text("cpu.core")) · \(index + 1): \(MetricFormat.percent(value))"))
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(kind.map { label($0) } ?? Text("cpu.core"))
|
||||
.accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user