fix(ui): 裁剪极小值进度条避免溢出圆角轨道

This commit is contained in:
2026-11-03 12:58:27 +08:00
parent 8a7303f6b2
commit df96d6853f
5 changed files with 33 additions and 8 deletions
+2
View File
@@ -180,3 +180,5 @@ SystemSampler 在首次采样前仅当 `KYMO_PANEL_PROBE=1` 执行一次 PanelCa
### 网络元数据与电池状态(已实现) ### 网络元数据与电池状态(已实现)
NET_RT_IFLIST2 吞吐枚举活动非 loopback 接口;总体只汇总活动 en 接口,VPN 等接口可独立查看但不计总体。getifaddrs 提供索引和本机 IPv4/IPv6,地址/活动状态改变、计数回退均重新建立速率基线;缺失不作为零。接口历史与总体历史分离,不请求公网地址。电池不存在与系统电源读取失败采用独立状态;健康查询异步完成后在下一次快照发布。 NET_RT_IFLIST2 吞吐枚举活动非 loopback 接口;总体只汇总活动 en 接口,VPN 等接口可独立查看但不计总体。getifaddrs 提供索引和本机 IPv4/IPv6,地址/活动状态改变、计数回退均重新建立速率基线;缺失不作为零。接口历史与总体历史分离,不请求公网地址。电池不存在与系统电源读取失败采用独立状态;健康查询异步完成后在下一次快照发布。
- `MetricProgressBar` 统一绘制每核心与进程 CPU 圆角进度条;有限值钳制到 0–1,非有限值按空轨道显示,零值不绘制填充。背景与填充整体按轨道 Capsule 裁剪,防止极窄填充超出圆角轨道。
+6
View File
@@ -116,3 +116,9 @@ Debug / Release 首版构建通过;不能据此标记 P1、P3、P4 退出条
用户截图中的规律性断续来自第二、第三序列的 StrokeStyle 虚线/点线参数,而非采样缺口。已移除数据曲线的 dash 参数,三条曲线均为圆角三次贝塞尔实线,继续通过颜色及图例区分。悬浮游标仍为虚线;真实缺失值/暂停边界的断开语义保留。 用户截图中的规律性断续来自第二、第三序列的 StrokeStyle 虚线/点线参数,而非采样缺口。已移除数据曲线的 dash 参数,三条曲线均为圆角三次贝塞尔实线,继续通过颜色及图例区分。悬浮游标仍为虚线;真实缺失值/暂停边界的断开语义保留。
验证:Debug 构建通过(默认执行沙盒阻止 Swift 宏插件后,在获准环境重试成功);从实际 PanelCurveCanvas 源码提取绘图组件,以 ImageRenderer 渲染三组连续样本,确认三色曲线均平滑连贯。该检查不等同于正式菜单栏面板交互或完整动画验收,本轮未重启用户应用。临时渲染脚本、图片、缓存与构建产物已清理。 验证:Debug 构建通过(默认执行沙盒阻止 Swift 宏插件后,在获准环境重试成功);从实际 PanelCurveCanvas 源码提取绘图组件,以 ImageRenderer 渲染三组连续样本,确认三色曲线均平滑连贯。该检查不等同于正式菜单栏面板交互或完整动画验收,本轮未重启用户应用。临时渲染脚本、图片、缓存与构建产物已清理。
### 极小值圆角进度条裁剪(2026-11-03)
核心与进程 CPU 进度条原先直接叠放两个 Capsule,填充宽度小于高度时未受到背景轨道的圆角轮廓约束。现共用 MetricProgressBar:有限比例钳制到 0–1,非有限输入显示空轨道;零值不绘制填充,背景与填充整体按轨道 Capsule 裁剪。
验证:Debug 构建通过;用实际组件在 82×7 和 45×6 两种尺寸下进行 ImageRenderer 渲染,检查 0、0.001、0.01、0.05、0.1、0.5、1、负值、超范围值、NaN 与无穷值,填充均不越过圆角轨道。未重启用户应用,正式面板交互未重复验证。临时渲染程序、图片、缓存与构建已清理。
+1 -4
View File
@@ -114,10 +114,7 @@ struct MenuPanelView: View {
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in
HStack(spacing: 3) { HStack(spacing: 3) {
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12) Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
GeometryReader { proxy in MetricProgressBar(value: value, color: Color("MetricCPU")).frame(height: 7)
Capsule().fill(Color("MetricCPU").opacity(0.15))
Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * value)
}.frame(height: 7)
}.help("\(index + 1): \(MetricFormat.percent(value))") }.help("\(index + 1): \(MetricFormat.percent(value))")
.accessibilityLabel(Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))") .accessibilityLabel(Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
} }
+2 -4
View File
@@ -44,10 +44,8 @@ struct ProcessTableView: View {
TableColumn("panel.path") { row in Text(verbatim: row.path ?? "--").lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary) }.width(min: 150, ideal: 400) TableColumn("panel.path") { row in Text(verbatim: row.path ?? "--").lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary) }.width(min: 150, ideal: 400)
TableColumn("CPU %") { row in TableColumn("CPU %") { row in
HStack(spacing: 6) { HStack(spacing: 6) {
GeometryReader { proxy in MetricProgressBar(value: (row.cpu ?? 0) / Double(max(1, logicalCPUCount)), color: Color("MetricCPU"))
Capsule().fill(Color("MetricCPU").opacity(0.15)) .frame(width: 45, height: 6).accessibilityHidden(true)
if let cpu = row.cpu { Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * min(1, max(0, cpu / Double(max(1, logicalCPUCount))))) }
}.frame(width: 45, height: 6).accessibilityHidden(true)
Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--").frame(maxWidth: .infinity, alignment: .trailing) Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--").frame(maxWidth: .infinity, alignment: .trailing)
} }
}.width(105) }.width(105)
@@ -0,0 +1,22 @@
import SwiftUI
/// Clips both layers to the track, including fills narrower than the track height.
struct MetricProgressBar: View {
let value: Double
let color: Color
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
var body: some View {
GeometryReader { proxy in
ZStack(alignment: .leading) {
Capsule().fill(color.opacity(0.15))
if fraction > 0 {
Capsule().fill(color).frame(width: proxy.size.width * fraction)
}
}
.frame(width: proxy.size.width, height: proxy.size.height)
.clipShape(Capsule())
}
}
}