From d87aa3ccc565fa4f58cbb51f00d3de3e721ba291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Sun, 15 Nov 2026 17:14:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E7=BC=A9=E5=B0=8F=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E5=B9=B6=E8=BF=98=E5=8E=9F=E8=AE=BE=E8=AE=A1=E7=A8=BF=E7=B4=A7?= =?UTF-8?q?=E5=87=91=E6=8E=92=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- docs/architecture.md | 8 +- docs/card-background-trends-plan.md | 19 ++ docs/development.md | 2 +- docs/testing.md | 4 +- docs/ui-design-standard.md | 43 ++-- kymo/Features/MenuBar/CPUCoreGrid.swift | 93 +++---- kymo/Features/MenuBar/MemoryDetailsView.swift | 27 +- kymo/Features/MenuBar/MemoryHeaderInfo.swift | 1 + .../MenuBar/MenuPanelView+Network.swift | 35 +-- .../MenuBar/MenuPanelView+ResourceCards.swift | 100 +++----- kymo/Features/MenuBar/MenuPanelView.swift | 2 +- kymo/Features/MenuBar/PanelLayout.swift | 16 +- .../Features/MenuBar/PanelResourceAudit.swift | 2 +- .../Features/MenuBar/StorageDetailsView.swift | 37 +-- kymo/Resources/CPUDetails.xcstrings | 69 +++++ kymo/Resources/Localizable.xcstrings | 242 ++++++++++++++++++ kymo/UI/Charts/NativePanelCurve.swift | 2 +- kymo/UI/Charts/PanelTrendChart.swift | 4 +- kymo/UI/Components/FanSpeedIndicator.swift | 8 +- kymo/UI/Components/MetricProgressBar.swift | 8 +- kymo/UI/Components/PanelStyle.swift | 5 +- kymo/UI/Components/ResourceCard.swift | 28 +- kymo/UI/Components/ResourceCardMetrics.swift | 19 +- kymoTests/CPUCoreGridChecks.swift | 16 +- kymoTests/MemoryHeaderChecks.swift | 2 + kymoTests/PanelLayoutChecks.swift | 44 ++-- kymoTests/ResourceCardChecks.swift | 38 ++- tools/check.py | 3 + 29 files changed, 609 insertions(+), 272 deletions(-) diff --git a/README.md b/README.md index f244c6a..317632d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点 ## 当前功能 -- CPU:总占用、用户态与系统态趋势、逐核数值与短条、温度;设备信息与开机时间位于公共底栏。 +- CPU:总占用、用户态与系统态趋势、按核型分行的逐核细条与悬浮数值、温度;设备信息与开机时间位于公共底栏。 - GPU:总占用与 Renderer / Tiler 趋势、核心数、温度和风扇转速。 - 内存:已用与总量、应用 / 联动 / 压缩分类、缓存、可用量、压力与 Swap。 - 存储:主目录所在卷容量、块设备读写速率、各本地卷容量、可读取的 SMART 寿命与通电时间。 @@ -12,7 +12,7 @@ Kymo 是 macOS 菜单栏资源监控工具。菜单栏常驻品牌图标,点 - 网络:接口切换、收发速率与累计字节、路径状态、本地和公网 IP 及复制。 - 进程:PID、名称、CPU、内存 footprint、CPU 平均功率、线程数和路径;支持搜索、列排序及复制,功率缺失始终排末。 -面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用三列两行网格,首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,同一行卡片等高;常规 960×630pt,小屏退为两列或单列,高度不足时滚动;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。彩色卡片采用大数值与底部背景趋势,淡色面积按真实连续段绘制,悬浮可查询各序列历史;数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 +面板支持固定显示、保持唤醒、暂停 / 恢复采样。概览采用三列两行网格,首行 CPU / GPU / 内存,次行电池 / 存储 / 网络,同一行卡片等高;常规 648×448pt,小屏退为两列或单列,高度不足时滚动;进程页独占内容区。概览停止进程 / footprint / 功率读取,进程页卸载资源图表并停用概览慢读取与公网任务,基础趋势跨页连续。彩色卡片采用大数值与底部背景趋势,淡色面积按真实连续段绘制,悬浮可查询各序列历史;数字、曲线和进度条随采样直接更新,不播放应用自定义动画或背景模糊特效;后台记录独立控制。面板刷新默认 2 秒;默认隐藏停止采样,可显式开启后台趋势并配置间隔(新配置 30 秒)。设置窗口提供系统 / 浅色 / 深色外观、简体中文 / 繁體中文 / English 和关于信息。 部分硬件指标依赖机型、驱动与权限,缺失值显示为 `--` 或对应状态。GPU 不提供逐核占用;耗电进程显示系统归属的 CPU 能量区间平均功率,注明可读覆盖范围,不代表完整应用总耗电。指标口径和限制见[监控指标](docs/monitoring.md)。 diff --git a/docs/architecture.md b/docs/architecture.md index 1fcf889..627fbd2 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -20,11 +20,11 @@ App 装配依赖,方向为 Features → UI → Core → 系统 API。Features 入口 kymoApp.main() 启动 NSApplication,由 ApplicationLifecycle 管理;应用以 accessory 模式启动,通过 NSHostingSceneRepresentation 注册 Settings。 -MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 960pt,常规高 630pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。 +MenuPanelController 拥有模板品牌 NSStatusItem 和无边框、可成为 key 的非激活 MonitoringPanel。左键切换面板,右键提供打开 / 隐藏、设置和退出。窗口以状态项所在屏幕可见区域为边界,水平居中,边缘至少留 16pt;最大宽 648pt,常规高 448pt,按卡片内容预算调整,最大高 800pt,并受实际屏幕限制。 -每次显式打开进入概览。概览采用三列两行网格:首行 CPU / GPU / 内存,次行电池 / 存储 / 网络。同一行按最高卡片的内容预算等高对齐;两行 CPU 核心与一行风扇时,两行卡片均高 264pt,列宽 308pt;标题、主数值、前景详情和底部 72pt 背景曲线采用统一几何规范。宽度小于 900pt 退为两列三行,小于 560pt 退为单列并将页签另放一行;重排保持上述逐行阅读顺序,高度不足时滚动。进程页独占中间内容区,两页共用窗口尺寸。底栏显示设备信息、开机时间和刷新间隔。 +每次显式打开进入概览。概览采用三列两行网格:首行 CPU / GPU / 内存,次行电池 / 存储 / 网络。同一行按最高卡片的内容预算等高对齐;两行 CPU 核型细条与一行风扇时,两行卡片均高 176pt,列宽 205⅓pt;标题、主数值、前景详情和底部 48pt 背景曲线采用统一几何规范。宽度小于 620pt 退为两列三行,小于 430pt 退为单列;小于 560pt 时页签另放一行。重排保持上述逐行阅读顺序,高度不足时滚动。进程页独占中间内容区,两页共用窗口尺寸。底栏显示设备信息、开机时间和刷新间隔。 -核心数由静态拓扑、硬件核数及快照共同确定;核心单元格按宽度增加行数,避免文字挤压。风扇在本次打开保留已发现槽位。实际卡片宽度和窗口 contentLayoutRect 驱动布局;仅结构预算变化才请求调整窗口高度。 +核心数由静态拓扑、硬件核数及快照共同确定;按核型纵向分行,每核保留独立占用细条与悬浮 / 辅助功能数值,核心较多时按宽度换行。风扇在本次打开保留已发现槽位。实际卡片宽度和窗口 contentLayoutRect 驱动布局;仅结构预算变化才请求调整窗口高度。 固定按钮切换 normal / floating 层级。未固定时外部交互或应用失活收起;固定仍可显式关闭。进程表 Esc 依次清空搜索、清除选择、退出搜索焦点,然后关闭面板。隐藏卸载内容、关闭底层窗口资源并移除外部鼠标监听,控制器保留窗口对象供重开。presentation.isOpen 控制内容装配,采样可见性同时要求窗口 isVisible 与 occlusionState 可见;完全遮挡降级采样而保留内容及交互状态。 @@ -55,7 +55,7 @@ SystemSampler actor 持有差分基线。CPU / 内存 Mach 查询取得的 host ## 展示与本地状态 -ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,完整传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。图表锚点和提示层在同一卡片宿主内处理。NativePanelCurve 绘制静态曲线、逐连续段闭合的低透明度实色面积和悬浮标记,只在数据、几何或外观变化时更新;悬浮沿用曲线 / 面积几何。ResourceCard 独立排列标题、大数值和详情,将 72pt 趋势贴合卡片底部,并统一 20pt 圆角、16pt 内边距和静态轻阴影。概览不显示常驻图例、坐标轴、网格或起止时间;CPU / GPU / 内存 / 电池仅绘制主序列,存储 / 网络绘制双序列,全部已有序列仍可悬浮查询。数字和进度条直接展示最终值;曲线绘图不创建动画、渐变或遮罩图层,卡片圆角裁切由宿主处理,不使用背景模糊。样式、指标前景契约和异常状态见 [UI 设计规范](ui-design-standard.md)。 +ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,完整传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。图表锚点和提示层在同一卡片宿主内处理。NativePanelCurve 绘制静态曲线、逐连续段闭合的低透明度实色面积和悬浮标记,只在数据、几何或外观变化时更新;悬浮沿用曲线 / 面积几何。ResourceCard 独立排列标题、大数值和详情,将 48pt 趋势贴合卡片底部,并统一 16pt 圆角、10pt 内边距和静态轻阴影。概览不显示常驻图例、坐标轴、网格或起止时间;CPU / GPU / 内存 / 电池仅绘制主序列,存储 / 网络绘制双序列,全部已有序列仍可悬浮查询。数字和进度条直接展示最终值;曲线绘图不创建动画、渐变或遮罩图层,卡片圆角裁切由宿主处理,不使用背景模糊。样式、指标前景契约和异常状态见 [UI 设计规范](ui-design-standard.md)。 概览与设置共享 NeutralTabPicker,使用静态 AppKit 按钮组;保留 tabGroup / tabButton 语义、选中值与键盘导航。绑定仅传递选择,页面和采样生命周期由上层负责。 diff --git a/docs/card-background-trends-plan.md b/docs/card-background-trends-plan.md index f31d520..1b5fc45 100644 --- a/docs/card-background-trends-plan.md +++ b/docs/card-background-trends-plan.md @@ -61,3 +61,22 @@ ResourceCard 统一容纳独立前景和底部 chart,主值与单位分层。N - 本地 Release 包:`dist/background-trends-v1/kymo-1.2-14-arm64-adhoc.zip`,arm64,最低 macOS 27.0;主应用与 XPC 原始签名 / 解压签名、Hardened Runtime、权限和归档内容检查通过,SHA-256 复核通过。 - SHA-256:`05af0be97d93a96d2e47583f595fbdd26a3dd117023177b6fe1ff0d60bfc6aa1`。本地 ad-hoc 签名,未公证;不代表其他 Mac 默认 Gatekeeper 放行。 - 随机测试副本、其容器、局部截图、临时脚本与 DerivedData 已清理。仅终止本轮测试路径下的进程,未操作用户安装副本;分发产物位于 Git 忽略目录。 + +## v1.1:按用户反馈收紧尺寸与图稿一致性 + +用户指出首版未严格还原图稿且尺寸过大,要求宽、高调整为当前 2/3。本轮以此修正规范:常规卡片 308×264 → 205⅓×176pt,面板最大宽 648pt、常规高 448pt,间距 6pt,底图 48pt;三列阈值 620pt、两列阈值 430pt。保持原生布局,不对整个界面做缩放变换。 + +还原图稿中的紧凑左对齐信息行:CPU 按核型逐行显示真实逐核细条(数值移至悬浮 / 辅助功能);GPU 核数与阶段值放在主数值下方;内存分类改为单行 + 容量条 + 可用量;电源状态和卷入口移到标题右侧;网络累计改为单行,实时数值用 primary、方向箭头保留语义色。采样、图表数据、复制和卷详情行为不变。 + +实施顺序:几何与组件 → 六卡内容 → 三语 / 窄屏 / 像素及构建检查 → 实际面板与图稿对照 → 更新分发包。验证仍采用前述独立检查,调整它们的几何断言并检查缩小后没有溢出;保留用户已有应用进程。 + +- [x] v1.1 实施与验证。 + +### v1.1 验证与交付 + +- Debug 构建通过;打包脚本的普通 Release 构建、原包 / 解压包签名、权限、Hardened Runtime 和内容检查通过。 +- 9 项受影响检查通过:PanelLayoutChecks、CPUCoreGridChecks、ResourceCardChecks、NativeMetricDrawingChecks、PanelWindowChecks、MemoryHeaderChecks、LocalizationChecks、FanChecks、NativeProcessTableChecks。末轮逐核格子、容量条和标签细化后,重跑 CPUCoreGridChecks / ResourceCardChecks / MemoryHeaderChecks / LocalizationChecks,通过;159 个三语资源键与格式参数检查通过。 +- 新增实际内存容量条像素检查;明确使用数值转换 UInt64 → Double,避免被解释为浮点位模式。分数点窗口尺寸以 AppKit 实际取整后的 content bounds 校验,背景图区保持贴边 48pt。 +- 面板自身截图对照图稿:简体浅色与英文深色 648×448pt,未见明显裁切;容量条、逐核格子、内存分类行、标题右侧电源 / 卷入口和单行网络累计均已核对。 +- 实际 AX 操作确认标题栏本地卷入口打开 / Cancel 关闭、520×360pt 窄屏滚动(滚动值由 0 变化)、进程页与概览切换恢复。原有真实指针悬浮、多屏与长期能耗边界仍适用。 +- 新包:`dist/background-trends-compact-v1/kymo-1.2-14-arm64-adhoc.zip`;旧包保留。本地 ad-hoc 签名、未公证,最低 macOS 27.0。SHA-256:`d6207b4a02c9576667efb5d41841ecf38de7af926e28451915896156cbb1da64`,校验通过。 diff --git a/docs/development.md b/docs/development.md index 95222bb..d5f4866 100644 --- a/docs/development.md +++ b/docs/development.md @@ -50,7 +50,7 @@ Debug 或显式 KYMO_AUDIT 构建可设置 KYMO_RESOURCE_AUDIT=1 驱动三轮真 | KYMO_AUDIT_PAGE=processes | 每轮打开后进入进程页 | | KYMO_AUDIT_CAPTURE=1 | 第一轮打开 10 秒后输出本应用面板 PNG 的 JSON 事件;与 INTERACTIVE / SIZE 组合时截取对应视口 | | KYMO_AUDIT_INTERACTIVE=1 | 打开固定面板供人工 / UI 工具操作,不自动退出 | -| KYMO_AUDIT_SIZE=480x500 | 交互模式限制测试视口,不覆盖自动尺寸;最小 480×360pt | +| KYMO_AUDIT_SIZE=480x500 | 交互模式限制测试视口,不覆盖自动尺寸;最小 360×360pt | | KYMO_XPC_AUDIT=1 | 运行请求重复 / 并发完成、超时及取消检查后退出 | 截图来自本应用 contentView,不采集桌面。生命周期驱动不证明菜单栏鼠标或 AX 事件已投递。tools/ 中 GPU 能力、负载和驱动调查程序不参与产品构建,也不代表已实现功能;使用前阅读对应入口。 diff --git a/docs/testing.md b/docs/testing.md index ad1309b..1dddc83 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -33,13 +33,13 @@ python3 tools/check.py --list | GPUStatisticsChecks、CPUTemperatureChecks、FanChecks、DiskHealthChecks | 当前 GPU 利用率与历史、温度范围与解码、风扇零值 / 无效值、SMART 边界与多物理存储拒绝合并 | | SensorScheduleChecks、BoundedProcessChecks | 各能力独立退避;真实受控子进程输出上限、超时、取消、异常退出与回收 | | ProcessEnergyChecks、ProcessEnergyReaderChecks、ProcessCPULiveChecks | UInt64 能量差分、身份 / UID / 缺失 / 回退 / 时间边界、受控本机能量增长和 Mach 时基 CPU 差分 | -| ProcessSelectionChecks、PanelLayoutChecks、CPUCoreGridChecks | 退出与 PID 复用、搜索 / 排序、960pt 三列两行 / 两列及单列窄屏预算、等高行与滚动边界、核心行数与边界 | +| ProcessSelectionChecks、PanelLayoutChecks、CPUCoreGridChecks | 退出与 PID 复用、搜索 / 排序、648pt 三列两行 / 两列及单列窄屏预算、等高行与滚动边界、核心行数与边界 | | PublicIPAddressChecks | 隔离 URLProtocol、600 秒成功 / 30 秒失败缓存、单调时间、持续刷新及取消,不发送真实请求 | | NetworkAddressChecks、ProcessIconCacheChecks | 沙盒下地址格式 / 速率;图标位图、尺寸、共享、过期、LRU 与严格预算 | | AppearancePreferencesChecks、LocalizationChecks、PresentationChecks | 外观与偏好隔离、语言持久化、编译资源、窗口显式 / 系统外观切换 | | CodeIdentityChecks、PanelAssetChecks、KeepAwakeChecks | 签名身份拒绝边界、编译颜色及对比度、真实 IOPM 断言开关与释放 | | NativeMetricDrawingChecks(--gui) | 实际曲线 / 静态面积像素、单点无虚构填充、隐藏序列隔离、缺失点接续与真实断点、悬浮缓存、无动画 / 渐变 / 遮罩、卸载 | -| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,266 / 308 / 460pt、浅深色及三语下的贴边图区、前景隔离和卸载 | +| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,190 / 205⅓ / 400pt、浅深色及三语下的贴边图区、前景隔离、实际内存容量条像素与卸载;比较 AppKit 实际尺寸,允许分数点窗口尺寸取整 | | NativeContentHostChecks(--gui) | 数字更新、父环境继承、挂载身份、有限尺寸和卸载 | | NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 | | TabPickerChecks、LanguageScopeChecks、SettingsWindowChecks(--gui) | 原生页签选择与键盘、已挂载语言即时切换、设置焦点 / 最小化恢复 / Dock 生命周期 | diff --git a/docs/ui-design-standard.md b/docs/ui-design-standard.md index 3c26900..44e7cb0 100644 --- a/docs/ui-design-standard.md +++ b/docs/ui-design-standard.md @@ -1,39 +1,40 @@ -# Kymo 界面设计规范 v1 +# Kymo 界面设计规范 v1.1 -2026-11-15 根据用户确认的[背景趋势设计稿](designs/card-background-trends-v1/README.md)制定。本文为实现与验收标准,效果图中的示例数据、品牌重绘与核心格子不作为数据或素材依据。 +2026-11-15 根据用户确认的[背景趋势设计稿](designs/card-background-trends-v1/README.md)制定,并按后续反馈将首版卡片宽、高缩至 2/3,恢复图稿中的紧凑左对齐排布。本文为实现与验收标准,效果图中的示例数据、品牌重绘与核心格子不作为数据或素材依据。 ## 适用范围与原则 统一概览六张资源卡片,保留三列两行、页签、工具栏、公共底栏及按页采样生命周期。Settings 与进程表保持现有交互;共用外观、语言与控件语义。依赖方向继续为 Features → UI → Core。 -优先级:真实数据与可读性 > 功能完整 > 视觉还原。所有缺失值显示 -- 或既有明确状态,不推导不存在的指标、不以装饰波形代替历史。无采样间的数值过渡、动态波纹、发光和背景模糊。 +按确认图稿保持数值层级、左对齐信息行与曲线背景,并在用户指定尺寸内实现。所有缺失值显示 -- 或既有明确状态,不推导不存在的指标、不以装饰波形代替历史。无采样间的数值过渡、动态波纹、发光和背景模糊。 ## 布局与尺寸(pt) | 项目 | 标准 | | --- | --- | -| 面板 | 最大宽 960,最大高 800;屏幕边缘至少 16;常规高 630 | -| 网格 | ≥900 宽为三列;560–899 为两列;<560 为单列;不足高时仅中间区域滚动 | +| 面板 | 最大宽 648,最大高 800;屏幕边缘至少 16;常规高 448 | +| 网格 | ≥620 宽为三列;430–619 为两列;<430 为单列;不足高时仅中间区域滚动 | | 顺序 | CPU / GPU / 内存 / 电池 / 存储 / 网络,按行阅读,同行等高 | -| 面板内边距 / 卡片间距 | 10 / 8;常规卡片宽 308 | -| 卡片 | 基础高 264,圆角 20,前景内边距 16 | -| 动态高度 | CPU 超过两行核心后每行增加 26;GPU 超过一行风扇后每行增加 20;不裁掉硬件数据 | -| 标题 / 主值区域 | 标题行 20,主值行 44,区域间距 6 | -| 背景趋势 | 卡片底部 72,横向贴边,按卡片圆角裁切;前景和图层预留独立空间 | +| 面板内边距 / 卡片间距 | 10 / 6;常规卡片宽 205⅓ | +| 卡片 | 基础高 176,圆角 16,前景内边距 10 | +| 动态高度 | CPU 按核型纵向分组,两行细条基础预算,超出每行增加 14;GPU 超过一行风扇后每行增加 14;不裁掉硬件数据 | +| 标题 / 主值区域 | 标题行 14,主值行 34,区域间距 4 | +| 背景趋势 | 卡片底部 48,横向贴边,按卡片圆角裁切;前景和图层预留独立空间 | +| 逐核格子 | 8×8、圆角 2;按核型左对齐,各格独立表达该核心占用,核型短标签宽 44 | | 顶栏 / 底栏 | 沿用 32(窄屏 64)/ 26;页签与操作可键盘访问 | ## 字体、颜色与层级 - 使用系统字体、现有品牌图像和 SF Symbols;数值使用等宽数字。 -- 卡片标题 14 semibold,主数值 36 semibold,单位 14 medium;双指标网络主数值 23、单位 11,避免挤压。必要时主值最多缩至 75%,全文保留为辅助说明。 -- 辅助指标 10–11;强调值 medium;悬浮提示 10。辅助内容可用固定行或自适应换行,但不能被背景曲线穿过。 -- 主数值使用 primary,提高浅深色对比度;CPU 青绿(MetricCPU)、GPU 玫红(MetricGPU)、内存蓝(MemoryApplication)、电池绿(MetricBattery)、存储琥珀(MetricDisk)、下载蓝(MetricMemory)、上传琥珀(SeriesUpload)。所有颜色来自 Assets。 +- 卡片标题 11 semibold,主数值 28 semibold,单位 12 medium;双指标网络主数值 16、单位 9,避免挤压。必要时主值最多缩至 75%,全文保留为辅助说明。 +- 辅助指标 8–9;强调值 medium;悬浮提示 9。辅助内容使用紧凑左对齐信息行,不能被背景曲线穿过。 +- 主数值使用 primary,提高浅深色对比度;网络仅方向箭头着色。CPU 青绿(MetricCPU)、GPU 玫红(MetricGPU)、内存蓝(MemoryApplication)、电池绿(MetricBattery)、存储琥珀(MetricDisk)、下载蓝(MetricMemory)、上传琥珀(SeriesUpload)。所有颜色来自 Assets。 - 温度在标题右侧;CPU ≥90°C 使用红色和既有高温说明。内存压力沿用正常 / 警告 / 严重颜色和文字,不能仅靠颜色传达状态。 -- 卡片采用 PanelCard、面板采用 PanelBackground 的浅深色资源。边框为 primary 6%–10%;静态轻阴影半径 6、纵偏移 2,不给文字或曲线单独加阴影。 +- 卡片采用 PanelCard、面板采用 PanelBackground 的浅深色资源。边框为 primary 浅色 2.5% / 深色 6%;静态轻阴影半径 4、纵偏移 1,不给文字或曲线单独加阴影。 ## 曲线与悬浮 -- 移除常驻图例、坐标轴、网格、起止时间与独立图框。背景曲线线宽 1.8,填充为同色静态实色透明度:浅色 12%、深色 16%;不使用渐变层、遮罩层或动画层。 +- 移除常驻图例、坐标轴、网格、起止时间与独立图框。背景曲线线宽 1.4,填充为同色静态实色透明度:浅色 12%、深色 16%;不使用渐变层、遮罩层或动画层。 - CPU / GPU / 内存显示总量主曲线,保留其全部历史序列供悬浮查询。电池背景显示电量,功率在悬浮中单独注明 W,不能与电量共用未解释的尺度。存储与网络显示双曲线、共用速率尺度。 - 百分比固定 0–100%;内存固定当前物理总量;速率保留既有自动范围及延迟缩小策略,不为视觉任意改变振幅。 - 时间使用真实采样日期;有效 0 保留,nil / 非有限数值不补值。沿用既有缺失节点接续与显式断点 / 长空档策略。面积按每个连续段分别闭合,不能填过暂停空档。 @@ -45,12 +46,12 @@ | 卡片 | 必须保留的前景与入口 | | --- | --- | -| CPU | 总占用、温度 / 高温状态、用户态 / 系统态、真实核型分组与每核数值 / 短条;禁止把核数画成亮灯计数 | -| GPU | 总占用、温度、核心数、Renderer / Tiler、已发现风扇转速或等待状态 | -| 内存 | 已用 / 总量 GiB、占用率、压力、分类容量条、应用 / 联动 / 压缩 / 可用;压力提示保留缓存和 Swap | -| 电池 | 电量、功率、电源、健康、循环、估时;无电池、失败、外接电源不适用状态 | -| 存储 | 已用 / 总量 GB、可用、读写速率、剩余寿命、通电时间、本地卷弹出层与口径说明 | -| 网络 | 收发速率、累计收发、接口选择与路径状态、公网 / 本地 IP、全文提示 / 选择 / 复制 | +| CPU | 总占用、温度 / 高温状态、左对齐用户 / 系统;按核型纵向分行的独立逐核细条,数值通过悬浮和辅助功能提供;禁止把核数画成亮灯计数 | +| GPU | 总占用、温度;主值下一行核心数与 Renderer / Tiler,再显示风扇转速或等待状态 | +| 内存 | 已用 / 总量 GiB、压力标签;应用 / 联动 / 压缩单行、容量条、可用量;占用率、缓存和 Swap 保留在压力提示中 | +| 电池 | 电量;电源在标题右侧;功率、健康 / 循环、估时依次左对齐;保留无电池、失败和不适用状态 | +| 存储 | 已用 / 总量 GB;本地卷入口在标题右侧;可用、读写、寿命 / 通电依次左对齐;保留卷弹出层与口径说明 | +| 网络 | 黑白主数值与着色方向箭头;单行累计收发;标题右侧接口与路径状态;两行公网 / 本地 IP 及全文提示 / 选择 / 复制 | 三语必须复用或补齐资源键;单位延续现有口径。长 IPv6、设备名和大数值可截断,但通过悬浮或复制取得完整内容。固定、暂停、保持唤醒与设置流程维持原语义。 diff --git a/kymo/Features/MenuBar/CPUCoreGrid.swift b/kymo/Features/MenuBar/CPUCoreGrid.swift index 5e79689..82c5bf4 100644 --- a/kymo/Features/MenuBar/CPUCoreGrid.swift +++ b/kymo/Features/MenuBar/CPUCoreGrid.swift @@ -1,6 +1,6 @@ import SwiftUI -/// Keep two balanced rows when possible; add rows to preserve readable core values. +/// One row per core kind; every equal-width meter represents one real core. struct CPUCoreGrid: View { let values: [Double] let kinds: [Int: CPUCoreTopology.Kind] @@ -14,8 +14,18 @@ struct CPUCoreGrid: View { } } - private func label(_ kind: CPUCoreTopology.Kind) -> Text { - switch kind { + private func label(_ kind: CPUCoreTopology.Kind, compact: Bool = false) -> Text { + if compact { + switch kind { + case .efficiency: return Text("cpu.kind.efficiencyShort", tableName: "CPUDetails") + case .middle: return Text("cpu.kind.performanceShort", tableName: "CPUDetails") + case .performance: + return kinds.values.contains(.middle) + ? Text("cpu.kind.superShort", tableName: "CPUDetails") + : Text("cpu.kind.performanceShort", tableName: "CPUDetails") + } + } + return switch kind { case .efficiency: Text("cpu.kind.efficiency", tableName: "CPUDetails") case .middle: Text("cpu.kind.performance", tableName: "CPUDetails") case .performance: @@ -30,80 +40,73 @@ struct CPUCoreGrid: View { return order.map { kind in (0.. [CGFloat] { - let weights = groups.map { CGFloat(($0.count + 1) / 2) } - let total = max(1, weights.reduce(0, +)) - let available = max(0, width - CGFloat(max(0, groups.count - 1)) * 13) - return weights.map { available * $0 / total } + let available = width.isFinite ? max(0, width - labelWidth - 6) : 0 + return Array(repeating: available, count: groups.count) } var body: some View { let groups = Self.groups(count: values.count, kinds: kinds) GeometryReader { geometry in let widths = Self.groupWidths(groups: groups, width: geometry.size.width) - HStack(alignment: .top, spacing: 6) { + VStack(alignment: .leading, spacing: 4) { ForEach(groups.indices, id: \.self) { group in - if group > 0 { - Rectangle().fill(.primary.opacity(0.08)).frame(width: 1) - } - VStack(alignment: .leading, spacing: 5) { - HStack(spacing: 3) { - Circle().fill(color(kinds[groups[group][0]])).frame(width: 5, height: 5) - if let kind = kinds[groups[group][0]] { label(kind) } + HStack(alignment: .top, spacing: 6) { + HStack(spacing: 2) { + Circle().fill(color(kinds[groups[group][0]])).frame(width: 3, height: 3) + if let kind = kinds[groups[group][0]] { label(kind, compact: true) } else { Text("cpu.core") } Text(verbatim: "\(groups[group].count)").foregroundStyle(.secondary) } - .font(.system(size: 9, weight: .medium)) - .lineLimit(1).minimumScaleFactor(0.6) + .font(.system(size: 8, weight: .medium)) + .lineLimit(1).minimumScaleFactor(0.65) + .frame(width: Self.labelWidth, height: CPUCoreGridLayout.rowHeight, alignment: .leading) CPUCoreGridLayout { - ForEach(groups[group], id: \.self) { index in - core(index: index) - } + ForEach(groups[group], id: \.self) { index in core(index: index) } } - }.frame(width: widths[group], alignment: .topLeading) + .frame(width: widths[group]) + } } } } - .frame(height: 15 + CGFloat(maxRows(groups: groups)) * 22 + CGFloat(max(0, maxRows(groups: groups) - 1)) * 4) - .padding(.vertical, 1) + .frame(height: gridHeight(groups: groups)) } - // Match the content width so row reservation agrees with placement. - var availableWidth: CGFloat = 380 + var availableWidth: CGFloat = 185 - private func maxRows(groups: [[Int]]) -> Int { + private func gridHeight(groups: [[Int]]) -> CGFloat { let widths = Self.groupWidths(groups: groups, width: availableWidth) - return zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0 + let rows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.reduce(0, +) + return CGFloat(rows) * CPUCoreGridLayout.rowHeight + CGFloat(max(0, rows - 1)) * CPUCoreGridLayout.rowSpacing } private func core(index: Int) -> some View { let kind = kinds[index] - let value = values[index].isFinite ? min(1, max(0, values[index])) : 0 - 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))") + let measured = values[index].isFinite ? values[index] : nil + return MetricProgressBar(value: measured ?? 0, color: color(kind), cornerRadius: 2) + .frame(height: 8) + .frame(maxWidth: .infinity, maxHeight: .infinity) + .help(Text("\(kind.map { label($0) } ?? Text("cpu.core")) · \(index + 1): \(MetricFormat.percent(measured))")) + .accessibilityElement(children: .ignore) + .accessibilityLabel(kind.map { label($0) } ?? Text("cpu.core")) + .accessibilityValue("\(index + 1): \(MetricFormat.percent(measured))") } } struct CPUCoreGridLayout: Layout { - static let columnSpacing: CGFloat = 6 + static let columnSpacing: CGFloat = 3 static let rowSpacing: CGFloat = 4 - static let rowHeight: CGFloat = 22 - static let minimumTwoRowCellWidth: CGFloat = 16 + static let rowHeight: CGFloat = 10 + static let minimumCellWidth: CGFloat = 8 static func rowCounts(count: Int, width: CGFloat) -> [Int] { guard count > 0 else { return [] } guard count > 1 else { return [1] } 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 capacity = max(1, Int(min(CGFloat(count), (usableWidth + columnSpacing) / (minimumCellWidth + columnSpacing)))) + let rows = max(1, (count + capacity - 1) / capacity) let quotient = count / rows, remainder = count % rows return (0.. 0 else { return } - let spacing = min(Self.columnSpacing, max(0, (bounds.width / CGFloat(columns) - 18) / 2)) - let cellWidth = max(0, (bounds.width - CGFloat(columns - 1) * spacing) / CGFloat(columns)) + let spacing = min(Self.columnSpacing, max(0, (bounds.width / CGFloat(columns) - Self.minimumCellWidth) / 2)) + let cellWidth = min(Self.minimumCellWidth, max(0, (bounds.width - CGFloat(columns - 1) * spacing) / CGFloat(columns))) var index = 0 for (row, count) in rows.enumerated() { for column in 0.. 0 { Text("·").foregroundStyle(.secondary) } + HStack(spacing: 2) { + Text(labels[index]) + MetricText(value: String(format: "%.1f", Double(values[index]) / 1_073_741_824)) + } + .help(Text(MetricFormat.memory(values[index]))) } + Text(verbatim: "GiB") } + .font(.system(size: 8)).foregroundStyle(.secondary) + .lineLimit(1).minimumScaleFactor(0.75) + CapacityBar(values: values.map { Double($0) }, colors: colors, total: Double(memory.total), height: 4) + HStack(spacing: 4) { + Text("memory.available").foregroundStyle(.secondary) + MetricText(value: MetricFormat.memory(memory.available)) + }.font(.system(size: 9)).lineLimit(1) } .accessibilityElement(children: .contain) .accessibilityLabel(Text("memory.distribution")) } - } diff --git a/kymo/Features/MenuBar/MemoryHeaderInfo.swift b/kymo/Features/MenuBar/MemoryHeaderInfo.swift index 875bd0f..ab2d8b9 100644 --- a/kymo/Features/MenuBar/MemoryHeaderInfo.swift +++ b/kymo/Features/MenuBar/MemoryHeaderInfo.swift @@ -16,6 +16,7 @@ struct MemoryHeaderInfo { } var title: String { pressure.key.map(localized) ?? "--" } + var badgeTitle: String { pressure.key == nil ? "--" : localized("memory.pressurePrefix") + title } var color: Color { pressure.color } var help: String { "\(localized("memory.pressure")): \(title)\n" diff --git a/kymo/Features/MenuBar/MenuPanelView+Network.swift b/kymo/Features/MenuBar/MenuPanelView+Network.swift index d4675bd..5c19dde 100644 --- a/kymo/Features/MenuBar/MenuPanelView+Network.swift +++ b/kymo/Features/MenuBar/MenuPanelView+Network.swift @@ -15,21 +15,21 @@ extension MenuPanelView { ).id(selectedInterface) } ) { - HStack(spacing: 12) { - networkTotal( - "network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }), - symbol: "arrow.down", color: Color("MetricMemory")) - networkTotal( - "network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }), - symbol: "arrow.up", color: Color("SeriesUpload")) - } - VStack(spacing: 4) { + HStack(spacing: 3) { + Text("network.totalShort").foregroundStyle(.secondary) + Image(systemName: "arrow.down").foregroundStyle(Color("MetricMemory")) + MetricText(value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received })) + Text("·").foregroundStyle(.secondary) + Image(systemName: "arrow.up").foregroundStyle(Color("SeriesUpload")) + MetricText(value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent })) + }.font(.system(size: 8)).lineLimit(1).minimumScaleFactor(0.75) + VStack(spacing: 3) { networkAddress("network.public", address: publicIPAddress) networkAddress( "network.local", address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first) } - .font(PanelStyle.label) + .font(.system(size: 9)) .accessibilityElement(children: .contain) .accessibilityLabel(Text("network.addresses")) } @@ -44,7 +44,7 @@ extension MenuPanelView { ForEach(snapshot.network ?? [], id: \.identity) { item in Text(verbatim: item.name).tag(item.identity) } - }.labelsHidden().controlSize(.mini).frame(maxWidth: 100) + }.labelsHidden().controlSize(.mini).fixedSize().frame(maxWidth: 70) } .help(Text(networkStatusLabel)) .accessibilityElement(children: .contain) @@ -54,7 +54,7 @@ extension MenuPanelView { func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View { HStack(spacing: 3) { Text(title).foregroundStyle(.secondary) - Text(verbatim: address ?? "--").font(PanelStyle.value).monospacedDigit().textSelection(.enabled) + Text(verbatim: address ?? "--").font(.system(size: 9, weight: .medium)).monospacedDigit().textSelection(.enabled) .help(Text(verbatim: address ?? "--")) .frame(maxWidth: .infinity, alignment: .leading) if let address { @@ -62,21 +62,12 @@ extension MenuPanelView { NSPasteboard.general.clearContents() NSPasteboard.general.setString(address, forType: .string) } label: { - Image(systemName: "doc.on.doc") + Image(systemName: "doc.on.doc").frame(width: 14, height: 14) } .buttonStyle(.plain).accessibilityLabel(Text("panel.copy")) } }.frame(maxWidth: .infinity, alignment: .leading).lineLimit(1) } - func networkTotal(_ title: LocalizedStringKey, value: String, symbol: String, color: Color) -> some View { - CardField(title: title) { - HStack(spacing: 3) { - Image(systemName: symbol).foregroundStyle(color) - MetricText(value: value) - } - } - } - var networkStatusLabel: LocalizedStringKey { switch snapshot.networkPath { case .available: "network.pathAvailable" diff --git a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift index 1ce7f6b..08e77d4 100644 --- a/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift +++ b/kymo/Features/MenuBar/MenuPanelView+ResourceCards.swift @@ -3,11 +3,11 @@ import SwiftUI extension MenuPanelView { func line(_ key: LocalizedStringKey, _ value: String) -> some View { - HStack(alignment: .firstTextBaseline) { - Text(key).font(PanelStyle.label).foregroundStyle(.secondary) + HStack(alignment: .firstTextBaseline, spacing: 4) { + Text(key).font(.system(size: 9)).foregroundStyle(.secondary) Spacer(minLength: 6) - MetricText(value: value).font(PanelStyle.value) - }.frame(height: 14) + MetricText(value: value).font(.system(size: 9, weight: .medium)) + }.frame(height: 12) } func inlineMetric(_ title: LocalizedStringKey, _ value: String) -> some View { @@ -15,8 +15,7 @@ extension MenuPanelView { Text(title).foregroundStyle(.secondary) MetricText(value: value).fontWeight(.medium) } - .font(.system(size: 11)).lineLimit(1).minimumScaleFactor(0.8) - .frame(maxWidth: .infinity, alignment: .leading) + .font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.8) } func batteryPowerLabel(_ battery: BatteryMetrics) -> LocalizedStringKey { @@ -43,10 +42,10 @@ extension MenuPanelView { boundaryDates: chartBoundaries, intervals: chartIntervals) } ) { - HStack(spacing: 12) { + HStack(spacing: 5) { inlineMetric("cpu.user", MetricFormat.percent(snapshot.cpu?.user)) inlineMetric("cpu.system", MetricFormat.percent(snapshot.cpu?.system)) - }.frame(height: 14) + }.frame(height: 12) if let cpu = snapshot.cpu { CPUCoreGrid( values: cpu.cores, kinds: CPUCoreTopology.cores, @@ -62,7 +61,6 @@ extension MenuPanelView { return ResourceCard( title: "metric.gpu", symbol: "square.grid.2x2", color: Color("MetricGPU"), value: MetricFormat.percent(snapshot.gpuUsage), status: snapshot.gpuTemperature.map { "\(Int($0.rounded()))°C" }, - detail: snapshot.gpu?.coreCount.map { String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), $0) }, chart: { PanelTrendChart( dates: samples.map(\.date), first: samples.map(\.gpu), @@ -72,24 +70,28 @@ extension MenuPanelView { expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals) } ) { - HStack(spacing: 12) { + HStack(spacing: 5) { + if let count = snapshot.gpu?.coreCount { + Text(verbatim: String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), count)) + .foregroundStyle(.secondary) + } inlineMetric("gpu.renderer", MetricFormat.percent(snapshot.gpu?.renderer)) inlineMetric("gpu.tiler", MetricFormat.percent(snapshot.gpu?.tiler)) - }.frame(height: 14) + }.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75).frame(height: 12) let fans = displayedFans if !fans.isEmpty { - LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 4) { + LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 5, alignment: .leading), count: min(2, fans.count)), spacing: 2) { ForEach(fans) { fan in FanSpeedIndicator( title: fans.count == 2 ? (fan.id == 0 ? Text("gpu.fanLeft") : Text("gpu.fanRight")) : Text("gpu.fanNumber \(fan.id + 1)"), rpm: fan.rpm) - .frame(height: 16) + .frame(height: 12) } } } else if snapshot.fans == nil { - Text("metric.waiting").font(PanelStyle.label) - .frame(maxWidth: .infinity, alignment: .leading).frame(height: 16) + Text("metric.waiting").font(.system(size: 9)) + .frame(maxWidth: .infinity, alignment: .leading).frame(height: 12) } } } @@ -101,8 +103,8 @@ extension MenuPanelView { value: snapshot.memory.map { String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824) } ?? "--", - status: snapshot.memory.map { MetricFormat.percent($0.usage) }, - detail: header.title, detailColor: header.color, detailHelp: header.help, + detail: header.badgeTitle, detailColor: snapshot.memory?.pressure == 1 ? Color("MetricBattery") : header.color, + detailHelp: header.help + "\n" + MetricFormat.percent(snapshot.memory?.usage), chart: { PanelTrendChart( dates: samples.map(\.date), @@ -131,6 +133,9 @@ extension MenuPanelView { format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000, Double($0.total) / 1_000_000_000) } ?? "--", + headerAccessory: AnyView(Button { showVolumes.toggle() } label: { + HStack(spacing: 2) { Text("disk.localVolumes"); Image(systemName: "chevron.right").font(.system(size: 7)) } + }.font(.system(size: 9)).buttonStyle(.plain).help(Text("disk.viewDetails"))), chart: { PanelTrendChart( dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"), @@ -139,13 +144,7 @@ extension MenuPanelView { ) } ) { - HStack(spacing: 12) { - inlineMetric("disk.read", MetricFormat.rate(snapshot.diskIO?.read)) - inlineMetric("disk.write", MetricFormat.rate(snapshot.diskIO?.written)) - }.frame(height: 14) - StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth) { - showVolumes.toggle() - } + StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth, io: snapshot.diskIO) .popover(isPresented: $showVolumes) { VStack(alignment: .leading, spacing: 8) { Text("disk.homeVolume") @@ -171,6 +170,7 @@ extension MenuPanelView { ResourceCard( title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"), value: MetricFormat.percent(snapshot.battery?.charge), + status: snapshot.battery.map { AppLocalization.string($0.externalPower ? "battery.acPower" : "battery.batterySource", locale: locale) }, chart: { PanelTrendChart( dates: samples.map(\.date), @@ -189,49 +189,33 @@ extension MenuPanelView { ) } ) { - inlineMetric(snapshot.battery.map(batteryPowerLabel) ?? "battery.power", MetricFormat.watts(snapshot.battery?.power)) - .frame(height: 14) + inlineMetric("battery.powerShort", MetricFormat.watts(snapshot.battery?.power)) + .frame(height: 12) if let battery = snapshot.battery { batteryDetails(battery) } else { Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary) - .font(PanelStyle.label).frame(maxWidth: .infinity).frame(height: 32) + .font(.system(size: 9)).frame(maxWidth: .infinity).frame(height: 32) } } } private func batteryDetails(_ battery: BatteryMetrics) -> some View { - VStack(alignment: .leading, spacing: 2) { - HStack(alignment: .top, spacing: 10) { - VStack(spacing: 4) { - line("battery.health", MetricFormat.percent(battery.health)) - HStack { - Text("battery.powerSource").foregroundStyle(.secondary) - Spacer(minLength: 4) - Text(battery.externalPower ? "battery.acPower" : "battery.batterySource").font(PanelStyle.value) - }.frame(height: 14) - } - Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 32) - VStack(spacing: 4) { - line("battery.cycles", battery.cycles.map(String.init) ?? "--") - HStack { - Text("battery.timeEstimate").foregroundStyle(.secondary) - Spacer(minLength: 4) - if battery.externalPower { - Text("battery.notApplicableShort").font(PanelStyle.value) - .help(Text("battery.timeNotApplicable")) - } else if let minutes = battery.minutesRemaining { - MetricText(value: "\(minutes) min").font(PanelStyle.value) - } else { - Text("battery.timeUnknown").font(PanelStyle.value) - } - }.frame(height: 14) + VStack(alignment: .leading, spacing: 3) { + HStack(spacing: 8) { + inlineMetric("battery.healthShort", MetricFormat.percent(battery.health)) + inlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--") + } + HStack(spacing: 4) { + Text("battery.timeShort").foregroundStyle(.secondary) + if battery.externalPower { + Text("battery.notApplicableShort").help(Text("battery.timeNotApplicable")) + } else if let minutes = battery.minutesRemaining { + MetricText(value: "\(minutes) min") + } else { + Text("battery.timeUnknown") } } - .font(PanelStyle.label) - .lineLimit(1) - .frame(height: 32) - - }.frame(maxWidth: .infinity, alignment: .topLeading) + } + .font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75) } - } diff --git a/kymo/Features/MenuBar/MenuPanelView.swift b/kymo/Features/MenuBar/MenuPanelView.swift index be0c78b..1b483dd 100644 --- a/kymo/Features/MenuBar/MenuPanelView.swift +++ b/kymo/Features/MenuBar/MenuPanelView.swift @@ -35,7 +35,7 @@ struct MenuPanelView: View { let coreCount = max(CPUCoreTopology.cores.count, ProcessInfo.processInfo.processorCount, snapshot.cpu?.cores.count ?? 0) let groups = CPUCoreGrid.groups(count: coreCount, kinds: CPUCoreTopology.cores) let widths = CPUCoreGrid.groupWidths(groups: groups, width: cardContentWidth) - let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0 + let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.reduce(0, +) let fanCount = reservedFanCount > 0 ? max(reservedFanCount, snapshot.fans?.count ?? 0) : snapshot.fans?.count return PanelLayout.cardHeights(coreRows: coreRows, fanCount: fanCount) } diff --git a/kymo/Features/MenuBar/PanelLayout.swift b/kymo/Features/MenuBar/PanelLayout.swift index b6918c6..d816f90 100644 --- a/kymo/Features/MenuBar/PanelLayout.swift +++ b/kymo/Features/MenuBar/PanelLayout.swift @@ -7,13 +7,13 @@ nonisolated enum PanelCard: Int, CaseIterable { nonisolated enum PanelLayout { static let footerHeight: CGFloat = 26 - static let maximumWidth: CGFloat = 960 + static let maximumWidth: CGFloat = ResourceCardMetrics.preferredWidth * 3 + 32 static let maximumHeight: CGFloat = 800 static func headerHeight(width: CGFloat) -> CGFloat { width >= 560 ? 32 : 64 } - static func columns(width: CGFloat) -> Int { width >= 900 ? 3 : width >= 560 ? 2 : 1 } + static func columns(width: CGFloat) -> Int { width >= 620 ? 3 : width >= 430 ? 2 : 1 } static func cardWidth(size: CGSize) -> CGFloat { let count = columns(width: size.width) - return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count)) + return max(0, (size.width - 20 - CGFloat(count - 1) * 6) / CGFloat(count)) } /// Keep reading order stable across three-, two- and single-column grids. @@ -29,8 +29,8 @@ nonisolated enum PanelLayout { static func cardHeights(coreRows: Int, fanCount: Int?) -> [PanelCard: CGFloat] { let base = ResourceCardMetrics.minimumHeight let fanRows = fanCount.map { (max(0, $0) + 1) / 2 } ?? 1 - return [.cpu: base + CGFloat(max(0, coreRows - 2)) * 26, - .gpu: base + CGFloat(max(0, fanRows - 1)) * 20, + return [.cpu: base + CGFloat(max(0, coreRows - 2)) * 14, + .gpu: base + CGFloat(max(0, fanRows - 1)) * 14, .memory: base, .battery: base, .storage: base, .network: base] } @@ -42,12 +42,12 @@ nonisolated enum PanelLayout { static func resourceHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat { let rows = rowHeights(columns: columns, heights: heights) - return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8 + return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 6 } static func preferredHeight(width: CGFloat, heights: [PanelCard: CGFloat]) -> CGFloat { min(maximumHeight, resourceHeight(columns: columns(width: width), heights: heights) - + 20 + headerHeight(width: width) + footerHeight + 16) + + 20 + headerHeight(width: width) + footerHeight + 12) } static var defaultHeight: CGFloat { @@ -56,7 +56,7 @@ nonisolated enum PanelLayout { static func needsResourceScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool { resourceHeight(columns: columns(width: size.width), heights: heights) - > size.height - 20 - headerHeight(width: size.width) - footerHeight - 16 + > size.height - 20 - headerHeight(width: size.width) - footerHeight - 12 } static func contentSize(visible: CGRect, chrome: CGSize = .zero, preferredHeight: CGFloat? = nil) -> CGSize { diff --git a/kymo/Features/MenuBar/PanelResourceAudit.swift b/kymo/Features/MenuBar/PanelResourceAudit.swift index 1ff7c8f..583eb55 100644 --- a/kymo/Features/MenuBar/PanelResourceAudit.swift +++ b/kymo/Features/MenuBar/PanelResourceAudit.swift @@ -40,7 +40,7 @@ import AppKit controller.show() if let value = ProcessInfo.processInfo.environment["KYMO_AUDIT_SIZE"] { let parts = value.split(separator: "x").compactMap { Double($0) } - if parts.count == 2, parts.allSatisfy({ $0.isFinite }), parts[0] >= 480, parts[1] >= 360 { + if parts.count == 2, parts.allSatisfy({ $0.isFinite }), parts[0] >= 360, parts[1] >= 360 { controller.panel.setContentSize(CGSize(width: min(parts[0], controller.panel.frame.width), height: min(parts[1], controller.panel.frame.height))) } diff --git a/kymo/Features/MenuBar/StorageDetailsView.swift b/kymo/Features/MenuBar/StorageDetailsView.swift index f00f6a8..a855fd5 100644 --- a/kymo/Features/MenuBar/StorageDetailsView.swift +++ b/kymo/Features/MenuBar/StorageDetailsView.swift @@ -3,39 +3,28 @@ import SwiftUI struct StorageDetailsView: View { let disk: DiskMetrics? let health: DiskHealthMetrics? - let showVolumes: () -> Void + let io: DiskIOMetrics? var body: some View { VStack(alignment: .leading, spacing: 4) { - HStack(spacing: 8) { - VStack(spacing: 4) { - field("memory.available", value: MetricFormat.bytes(disk?.available)) - field("disk.powerOnHours", value: health?.powerOnHours.map { "\($0) h" } ?? "--") - } - Divider().frame(height: 32) - VStack(spacing: 4) { - field("disk.remainingLife", value: MetricFormat.percent(health?.remainingLife)) - Button(action: showVolumes) { - HStack(spacing: 3) { - Text("disk.localVolumes") - Spacer(minLength: 3) - Image(systemName: "chevron.right").font(.system(size: 8)) - }.contentShape(.rect) - } - .buttonStyle(.plain).help(Text("disk.viewDetails")) - .frame(height: 14) - } - }.font(PanelStyle.label).lineLimit(1) + field("memory.available", value: MetricFormat.bytes(disk?.available)) + HStack(spacing: 6) { + field("disk.read", value: MetricFormat.rate(io?.read)) + field("disk.write", value: MetricFormat.rate(io?.written)) + } + HStack(spacing: 4) { + field("disk.lifeShort", value: MetricFormat.percent(health?.remainingLife)) + Text("·").foregroundStyle(.secondary) + field("disk.powerOnShort", value: health?.powerOnHours.map { "\($0) h" } ?? "--") + }.font(.system(size: 8)) } + .font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75) } private func field(_ title: LocalizedStringKey, value: String) -> some View { HStack(spacing: 3) { Text(title).foregroundStyle(.secondary).help(Text(title)) - Spacer(minLength: 3) - MetricText(value: value).font(PanelStyle.value) + MetricText(value: value) } - .frame(height: 14) - .frame(maxWidth: .infinity) } } diff --git a/kymo/Resources/CPUDetails.xcstrings b/kymo/Resources/CPUDetails.xcstrings index ee86353..00d0e50 100644 --- a/kymo/Resources/CPUDetails.xcstrings +++ b/kymo/Resources/CPUDetails.xcstrings @@ -92,6 +92,75 @@ } } } + }, + "cpu.kind.efficiencyShort": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "E-cores" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "能效核" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "能效核" + } + } + } + }, + "cpu.kind.performanceShort": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "P-cores" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "性能核" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "效能核" + } + } + } + }, + "cpu.kind.superShort": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "S-cores" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "超大核" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "超大核" + } + } + } } }, "version": "1.0" diff --git a/kymo/Resources/Localizable.xcstrings b/kymo/Resources/Localizable.xcstrings index a64cd00..86c47a6 100644 --- a/kymo/Resources/Localizable.xcstrings +++ b/kymo/Resources/Localizable.xcstrings @@ -1,6 +1,248 @@ { "sourceLanguage" : "en", "strings" : { + "disk.lifeShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Life" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "剩余寿命" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "剩餘壽命" + } + } + } + }, + "disk.powerOnShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "On-time" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "通电" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "通電" + } + } + } + }, + "battery.healthShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Health" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "健康" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "健康" + } + } + } + }, + "battery.cyclesShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Cycles" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "循环" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "循環" + } + } + } + }, + "battery.timeShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Time" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "续航" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "續航" + } + } + } + }, + "battery.powerShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Power" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "功率" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "功率" + } + } + } + }, + "memory.appShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "App" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "应用" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "應用" + } + } + } + }, + "memory.wiredShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Wired" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "联动" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "連動" + } + } + } + }, + "memory.compressedShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Compressed" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "压缩" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "壓縮" + } + } + } + }, + "memory.pressurePrefix" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Pressure " + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "压力" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "壓力" + } + } + } + }, + "network.totalShort" : { + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Total" + } + }, + "zh-Hans": { + "stringUnit": { + "state": "translated", + "value": "累计" + } + }, + "zh-Hant": { + "stringUnit": { + "state": "translated", + "value": "累計" + } + } + } + }, "battery.notApplicableShort" : { "localizations" : { "en" : { diff --git a/kymo/UI/Charts/NativePanelCurve.swift b/kymo/UI/Charts/NativePanelCurve.swift index d0c0b4f..6471513 100644 --- a/kymo/UI/Charts/NativePanelCurve.swift +++ b/kymo/UI/Charts/NativePanelCurve.swift @@ -192,7 +192,7 @@ struct NativePanelCurve: NSViewRepresentable { private final class SeriesLayer { let root = CALayer(), area = CAShapeLayer(), line = CAShapeLayer(), points = CAShapeLayer() init() { - line.fillColor = nil; line.lineWidth = 1.8; line.lineCap = .round; line.lineJoin = .round + line.fillColor = nil; line.lineWidth = 1.4; line.lineCap = .round; line.lineJoin = .round root.addSublayer(area); root.addSublayer(line); root.addSublayer(points) } func resize(_ bounds: CGRect) { diff --git a/kymo/UI/Charts/PanelTrendChart.swift b/kymo/UI/Charts/PanelTrendChart.swift index 2ba23d4..a3731e9 100644 --- a/kymo/UI/Charts/PanelTrendChart.swift +++ b/kymo/UI/Charts/PanelTrendChart.swift @@ -80,14 +80,14 @@ struct PanelTrendChart: View { } } private func tooltip(index: Int) -> some View { - VStack(alignment: .leading, spacing: 5) { + VStack(alignment: .leading, spacing: 3) { Text(dates[index], format: .dateTime.hour().minute().second()).foregroundStyle(.secondary) tooltipRow(firstLabel, values: first, tint: color, index: index) if !second.isEmpty { tooltipRow(secondLabel, values: second, tint: secondColor, format: secondValueFormat, index: index) } if !third.isEmpty { tooltipRow(thirdLabel, values: third, tint: thirdColor, index: index) } if !fourth.isEmpty { tooltipRow(fourthLabel, values: fourth, tint: fourthColor, index: index) } } - .font(.system(size: 10)).padding(8) + .font(.system(size: 9)).padding(6) .background { TooltipBackground() } .overlay(RoundedRectangle(cornerRadius: 7).strokeBorder(.primary.opacity(0.2))) } diff --git a/kymo/UI/Components/FanSpeedIndicator.swift b/kymo/UI/Components/FanSpeedIndicator.swift index 16af13b..1db18bf 100644 --- a/kymo/UI/Components/FanSpeedIndicator.swift +++ b/kymo/UI/Components/FanSpeedIndicator.swift @@ -5,15 +5,11 @@ struct FanSpeedIndicator: View { let rpm: Double? var body: some View { - HStack(spacing: 5) { - Image(systemName: "fanblades.fill") - .foregroundStyle(.secondary) - .frame(width: 14, height: 14).accessibilityHidden(true) + HStack(spacing: 4) { title.foregroundStyle(.secondary) - Spacer(minLength: 2) MetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM") .monospacedDigit().fontWeight(.medium) } - .font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7) + .font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7) } } diff --git a/kymo/UI/Components/MetricProgressBar.swift b/kymo/UI/Components/MetricProgressBar.swift index 4e6430f..82a3368 100644 --- a/kymo/UI/Components/MetricProgressBar.swift +++ b/kymo/UI/Components/MetricProgressBar.swift @@ -4,17 +4,19 @@ import SwiftUI struct MetricProgressBar: View { let value: Double let color: Color + var cornerRadius: CGFloat? = nil private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 } var body: some View { GeometryReader { proxy in + let shape = RoundedRectangle(cornerRadius: cornerRadius ?? proxy.size.height / 2, style: .continuous) ZStack(alignment: .leading) { - Capsule().fill(color.opacity(0.15)) - Capsule().fill(color).frame(width: proxy.size.width * fraction) + shape.fill(color.opacity(0.15)) + shape.fill(color).frame(width: proxy.size.width * fraction) } .frame(width: proxy.size.width, height: proxy.size.height) - .clipShape(Capsule()) + .clipShape(shape) .transaction { $0.animation = nil; $0.disablesAnimations = true } } } diff --git a/kymo/UI/Components/PanelStyle.swift b/kymo/UI/Components/PanelStyle.swift index fe7bcf4..a6b7937 100644 --- a/kymo/UI/Components/PanelStyle.swift +++ b/kymo/UI/Components/PanelStyle.swift @@ -7,7 +7,7 @@ enum PanelStyle { static let value = Font.system(size: 10, weight: .medium) static let legend = Font.system(size: 9) static let padding: CGFloat = 10 - static let gap: CGFloat = 8 + static let gap: CGFloat = 6 static let titleHeight: CGFloat = 20 } @@ -38,6 +38,7 @@ struct CapacityBar: View { let values: [Double] let colors: [Color] let total: Double + var height: CGFloat = 8 var body: some View { GeometryReader { bounds in @@ -49,7 +50,7 @@ struct CapacityBar: View { } .clipShape(Capsule()) } - .frame(height: 8) + .frame(height: height) .accessibilityHidden(true) } } diff --git a/kymo/UI/Components/ResourceCard.swift b/kymo/UI/Components/ResourceCard.swift index c23fc1c..c42a30a 100644 --- a/kymo/UI/Components/ResourceCard.swift +++ b/kymo/UI/Components/ResourceCard.swift @@ -29,7 +29,7 @@ struct ResourceCard: View { .frame(width: bounds.size.width, height: ResourceCardMetrics.plotHeight) VStack(alignment: .leading, spacing: ResourceCardMetrics.gap) { header - HStack(alignment: .firstTextBaseline, spacing: 12) { + HStack(alignment: .firstTextBaseline, spacing: 6) { MetricHeadline(value: value, compact: secondaryValue != nil, color: valueColor ?? .primary) if let secondaryValue { MetricHeadline(value: secondaryValue, compact: true, color: secondaryValueColor ?? .primary) @@ -40,18 +40,18 @@ struct ResourceCard: View { content() Spacer(minLength: 0) } - .font(PanelStyle.label) + .font(.system(size: 9)) .padding(ResourceCardMetrics.padding) .padding(.bottom, ResourceCardMetrics.plotHeight - ResourceCardMetrics.padding) .frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading) } .background(Color("PanelCard")) .clipShape(.rect(cornerRadius: ResourceCardMetrics.radius)) - .overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(0.07))) + .overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(colorScheme == .dark ? 0.06 : 0.025))) .background { RoundedRectangle(cornerRadius: ResourceCardMetrics.radius) .fill(Color("PanelCard")) - .shadow(color: .black.opacity(colorScheme == .dark ? 0.16 : 0.06), radius: 6, x: 0, y: 2) + .shadow(color: .black.opacity(colorScheme == .dark ? 0.12 : 0.05), radius: 4, x: 0, y: 1) } } .overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in @@ -77,19 +77,19 @@ struct ResourceCard: View { } icon: { Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color) } - .font(.system(size: 14, weight: .semibold)).fixedSize() + .font(.system(size: 11, weight: .semibold)).fixedSize() Spacer(minLength: 4) if let status { Text(verbatim: status) - .font(.system(size: 11, weight: .medium)) + .font(.system(size: 9, weight: .medium)) .foregroundStyle(statusWarning ? .red : .secondary) .help(warningText ?? Text(verbatim: status)) .accessibilityLabel(warningText.map { Text("\(status) \($0)") } ?? Text(verbatim: status)) } if let detail { Text(verbatim: detail) - .font(.system(size: 10, weight: .medium)).foregroundStyle(detailColor ?? .secondary) - .padding(.horizontal, 6).frame(height: 18) + .font(.system(size: 8, weight: .medium)).foregroundStyle(detailColor ?? .secondary) + .padding(.horizontal, 5).frame(height: 14) .background((detailColor ?? .primary).opacity(0.10), in: Capsule()) .lineLimit(1) .help(Text(verbatim: detailHelp ?? detail)) @@ -115,20 +115,20 @@ private struct MetricHeadline: View { } var body: some View { - HStack(alignment: .firstTextBaseline, spacing: 3) { + HStack(alignment: .firstTextBaseline, spacing: 2) { if let direction { Image(systemName: direction == "↓" ? "arrow.down" : "arrow.up") - .font(.system(size: 16, weight: .medium)) + .font(.system(size: 12, weight: .medium)).foregroundStyle(color) } Text(verbatim: parts.first.map(String.init) ?? value) - .font(.system(size: compact ? 23 : 36, weight: .semibold)) + .font(.system(size: compact ? 16 : 28, weight: .semibold)) if parts.count > 1 { Text(verbatim: String(parts[1])) - .font(.system(size: compact ? 11 : 14, weight: .medium)) - .foregroundStyle(Color.secondary) + .font(.system(size: compact ? 9 : 12, weight: .medium)) + .foregroundStyle(Color.primary.opacity(0.8)) } } - .monospacedDigit().foregroundStyle(color) + .monospacedDigit().foregroundStyle(.primary) .lineLimit(1).minimumScaleFactor(0.75) .frame(maxWidth: .infinity, alignment: .leading) .help(Text(verbatim: value)) diff --git a/kymo/UI/Components/ResourceCardMetrics.swift b/kymo/UI/Components/ResourceCardMetrics.swift index 4fa13fc..cd9ad92 100644 --- a/kymo/UI/Components/ResourceCardMetrics.swift +++ b/kymo/UI/Components/ResourceCardMetrics.swift @@ -1,13 +1,14 @@ import CoreGraphics -/// Shared geometry for resource foregrounds, background plots and panel budgets. +/// Compact native geometry: card width and height are 2/3 of the first implementation. nonisolated enum ResourceCardMetrics { - static let minimumHeight: CGFloat = 264 - static let padding: CGFloat = 16 - static let radius: CGFloat = 20 - static let plotHeight: CGFloat = 72 - static let titleHeight: CGFloat = 20 - static let headlineHeight: CGFloat = 44 - static let gap: CGFloat = 6 - static let tooltipMinimumY: CGFloat = 96 + static let preferredWidth: CGFloat = 308 * 2 / 3 + static let minimumHeight: CGFloat = 176 + static let padding: CGFloat = 10 + static let radius: CGFloat = 16 + static let plotHeight: CGFloat = 48 + static let titleHeight: CGFloat = 14 + static let headlineHeight: CGFloat = 34 + static let gap: CGFloat = 4 + static let tooltipMinimumY: CGFloat = 68 } diff --git a/kymoTests/CPUCoreGridChecks.swift b/kymoTests/CPUCoreGridChecks.swift index c0ab621..3caa489 100644 --- a/kymoTests/CPUCoreGridChecks.swift +++ b/kymoTests/CPUCoreGridChecks.swift @@ -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..= 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") } } diff --git a/kymoTests/MemoryHeaderChecks.swift b/kymoTests/MemoryHeaderChecks.swift index ee768da..5049034 100644 --- a/kymoTests/MemoryHeaderChecks.swift +++ b/kymoTests/MemoryHeaderChecks.swift @@ -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) diff --git a/kymoTests/PanelLayoutChecks.swift b/kymoTests/PanelLayoutChecks.swift index 5cbc7d5..2cb36a5 100644 --- a/kymoTests/PanelLayoutChecks.swift +++ b/kymoTests/PanelLayoutChecks.swift @@ -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 diff --git a/kymoTests/ResourceCardChecks.swift b/kymoTests/ResourceCardChecks.swift index 8729c4f..7e5b48e 100644 --- a/kymoTests/ResourceCardChecks.swift +++ b/kymoTests/ResourceCardChecks.swift @@ -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.. 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) } } diff --git a/tools/check.py b/tools/check.py index c7343f9..7cf08bf 100644 --- a/tools/check.py +++ b/tools/check.py @@ -69,6 +69,9 @@ CHECKS["ResourceCardChecks"] = [ "kymo/UI/Charts/PanelCurveFrame.swift", "kymo/UI/Charts/PanelCurveGeometry.swift", "kymo/UI/Charts/ChartTooltipLayer.swift", "kymo/Core/Extensions/MetricFormat.swift", ] +CHECKS["ResourceCardChecks"] = list(dict.fromkeys(CORE + CHECKS["ResourceCardChecks"] + [ + "kymo/Features/MenuBar/MemoryDetailsView.swift", +])) for name in ("PanelLayoutChecks", "PanelWindowChecks"): CHECKS[name].append("kymo/UI/Components/ResourceCardMetrics.swift")