refactor(ui): 将页签改为扁平胶囊并保留导航语义

This commit is contained in:
2026-11-08 22:21:19 +08:00
parent 8d3891966a
commit 28112bcf2e
9 changed files with 226 additions and 47 deletions
+2
View File
@@ -6,6 +6,8 @@
### 界面与性能
- 1.1(11):监控与设置的 Tab 改为与顶部操作组一致的扁平胶囊,移除系统液态玻璃外观;保留页面切换、选中态、键盘导航和辅助功能页签语义,位置与刷新间隔不变。
- 1.1(10):概览改为固定顺序的独立双列,卡片按内容预算定高;常规窗口由 640×800 缩至 640×706pt,顶部 Tab 与底部刷新间隔保留原位。趋势图压至 48pt,收紧核心 / 风扇 / 内存 / 存储 / 网络信息;高核心数增加可读行数,较矮屏幕继续滚动。
- 1.1(9):640pt 面板恢复顶部单行 Tab,刷新间隔移至底部右侧;同步调整工具栏高度预算,让常规六卡概览完整显示。
+4 -2
View File
@@ -66,7 +66,7 @@ CPU / GPU / 风扇合并为一次只读 XPC 请求,按到期类别选择读取
外观、语言和双采样间隔写入 UserDefaults。图钉、暂停、保持唤醒和进程表交互状态不作为持久化偏好。`AppLanguageScope` 将语言环境注入 AppKit 承载的 SwiftUI 内容,并处理即时刷新;原生菜单文案通过 `AppLocalization` 读取;编号风扇等 SwiftUI 文案保留为带参数的 `Text`,由当前应用语言环境解析。
面板和资源卡片使用颜色资产中的不透明背景,顶部操作组使用低透明度静态胶囊背景;不再以全窗口液态玻璃概念图作为实现依据。品牌图标与颜色以 Assets 为运行时来源。
面板和资源卡片使用颜色资产中的不透明背景,顶部操作组与页签使用低透明度静态胶囊背景;不再以全窗口液态玻璃概念图作为实现依据。品牌图标与颜色以 Assets 为运行时来源。
固定 frame 的面板宿主关闭 NSHostingView 自动尺寸协商。每张 ResourceCard 通过 UI 层 NativeContentHost 获得独立、固定尺寸的 NSHostingView,局部数据和状态更新在卡片宿主内处理;父层按稳定列顺序、内容行数和硬件拓扑计算卡片尺寸,并经 App 注入首选高度回调交给 MenuPanelController 约束到屏幕可用区域。窗口高度取较长列加顶部、底栏和间隔,两页共用外框;结构预算相同不触发重复 setFrame,数值刷新不改变高度。核心数优先使用静态拓扑 / 硬件核数,避免首帧无值收缩;风扇在本次打开保留已发现槽位,确认无风扇时可移除发现占位。完整 SwiftUI 环境注入子宿主,保留字体、前景样式、语言和外观;更新沿用原有挂载身份,卸载时清空子宿主内容。坐标、图例、悬浮偏好与提示层都保留在同一卡片宿主内,不跨原生边界传递锚点。趋势图的业务投影继续由 Features 管理;曲线 / 网格 / 悬浮标记与百分比圆环分别由 UI 层 NativePanelCurve、NativeMetricRing 绘制。保留 PanelCurveGeometry 的真实时间、缺失值与断点规则。
@@ -108,4 +108,6 @@ PublicIPAddressService 默认持有专用 ephemeral URLSession,URLCache / HTTP
CPU 逐核显示使用数值与静态短条,内存保留分布条;GPU 渲染器 / 分块器独立进度条和统计区、电池内的耗电前三列表已移除,存储重复容量条改为可用容量 / 健康 / 通电时长 / 卷入口文本。六张趋势保留既有真实时间及断点规则。页面布局和数据需求详见[实施记录](compact-tab-panel-plan.md)。
进一步收窄阶段中,概览与设置共享 UI/Components/NeutralTabPicker,保持中性色分段导航;窄卡片的内存趋势图例省略重复实时值,完整分类数值仍在内存分布区及悬浮中提供。外接电源的时间项简写为不适用,完整说明在提示中。独立双列和按内容定高已按[实施方案](compact-panel-refinement-plan.md)落实:趋势绘图区 48pt、分隔线竖向留白 2pt;内存使用率移至标题徽标,存储为双列文本,网络合并状态 / 接口及地址行。核心按至少 16pt 单元格动态增加行数,不再限制最多三行;超出屏幕时通过概览滚动访问。
进一步收窄阶段中,概览与设置共享 UI/Components/NeutralTabPicker,保持中性色分段导航。按后续扁平样式要求,控件改用静态绘制的 AppKit 按钮组,不调用系统分段控件的液态玻璃 bezel;设置 ToolbarItem 显式隐藏系统共享背景,避免宿主再次包裹玻璃。4pt 内边距、2pt 间距及底色 / 悬停 / 按下透明度与顶部操作组一致。当前页以选中底色和字重区分,辅助功能保留 tabGroup / tabButton 语义及选中值;原生按钮负责点击与焦点,左右 / Home / End 在页签内切换并转移焦点,Tab 键只停在当前页签。该组件只通过绑定传递选择,不管理页面生命周期或采样。
窄卡片的内存趋势图例省略重复实时值,完整分类数值仍在内存分布区及悬浮中提供。外接电源的时间项简写为不适用,完整说明在提示中。独立双列和按内容定高已按[实施方案](compact-panel-refinement-plan.md)落实:趋势绘图区 48pt、分隔线竖向留白 2pt;内存使用率移至标题徽标,存储为双列文本,网络合并状态 / 接口及地址行。核心按至少 16pt 单元格动态增加行数,不再限制最多三行;超出屏幕时通过概览滚动访问。
+16
View File
@@ -94,3 +94,19 @@ Tab 已改为共享 AppKit NSSegmentedControl(tabs role + capsule 样式),
- Core 采样及两页需求策略未修改,DetailDemandChecks 验证概览不枚举进程、进程页切换和基础历史连续。未重新测量功率或长期资源预算,不能把外框减少约 12% 解释成功耗同幅降低。
收尾:已清理本轮隔离构建、诊断 app、局部截图相关临时数据、脚本、日志和随机偏好容器;保留最终 1.1(10)ZIP 与 SHA-256。仅退出本轮临时路径下的测试进程,未操作测试前已有的 /Applications/kymo.app(PID 55382)及其 XPC(PID 55384)。未安装到 Applications、未推送或发布。
## 用户修订:扁平页签(1.1(11))
用户要求页签使用与右侧操作组一致的扁平风格,同时继续承担页面导航职责。共享 NeutralTabPicker 改用静态绘制的 AppKit 按钮组:4pt 内边距、2pt 间距、0.04 底色、0.08 悬停和 0.16 按下反馈;当前页使用 0.10 选中底色与中等字重。没有材质、渐变、装饰阴影、动画或新定时任务。设置页 ToolbarItem 另行隐藏系统共享背景,避免工具栏给自定义控件再次包裹液态玻璃。
页签仍为单选导航,保留概览 / 进程、常规 / 关于的原选择绑定和页面生命周期;窗口尺寸、独立双列、顶部 Tab 及底部右侧刷新间隔不变。辅助功能使用 tabGroup / tabButton,每个页签仅暴露一个元素和真实选中值;显式处理辅助功能按下,避免自定义角色下原生按钮默认处理失效。原生按钮继续承担点击与焦点,左右 / Home / End 切换后焦点跟随,Tab 键只停在当前页签。
### 验证记录
- Debug 和交互诊断 Release 构建通过;没有 XCTest Target,使用独立检查程序。
- 5 项相关回归通过:TabPickerChecks、PanelLayoutChecks、PanelWindowChecks、SettingsWindowChecks、LanguageScopeChecks,另有 213 项三语目录及宿主权限检查通过。TabPickerChecks 覆盖双向绑定、点击 / AX 按下、角色 / 单一元素 / 选中值、方向键 / Home / End 与焦点、三语原地更新与选择保留;修正辅助功能元素重复后再次单独通过。
- 实际 CUA 检查中文深色和英文浅色面板,页签为静态扁平胶囊,与右侧操作组匹配,常规外框仍为 640×706pt,刷新输入仍在底部右侧。点击进程页与键盘 Tab → Left 返回概览均成功,辅助功能树显示正确页签角色、选中值和焦点。
- 设置页切到 About 后内容和选中态一致;发现工具栏自动共享玻璃背景并显式隐藏,最终英文浅色截图确认外层玻璃边框已消除。
- 本次仅改变呈现控件及设置工具栏背景,不改变 Core 采样和页签需求策略;未重测长期能耗,不将视觉扁平化解释为已测得的节能幅度。真实多屏及主观观感仍由用户验收。
普通 Release 1.1(11)打包、主程序 / XPC 签名、Hardened Runtime、权限、ZIP 解压复核及最终 SHA-256 校验通过。已清理本轮临时构建、诊断副本、日志和随机偏好容器,只退出临时路径下的测试进程;未操作测试前已有的 /Applications/kymo.app(PID 59142)及其 XPC(PID 59148)。保留最终 ZIP 与校验文件,未安装到 Applications、未推送或发布。
+3 -3
View File
@@ -2,7 +2,7 @@
## 适用范围
当前产物:Kymo 1.1(build 10),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。
当前产物:Kymo 1.1(build 11),macOS 27.0 及以上、Apple silicon arm64。Intel 或较低系统不在该产物支持范围。软件使用 ad-hoc 本地签名,未经过 Apple 公证,不是 Developer ID 官方分发包;下载后的系统提示取决于接收方安全策略。
## 构建与校验
@@ -10,10 +10,10 @@
python3 tools/package_release.py
```
默认输出:`dist/kymo-1.1-10-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件:
默认输出:`dist/kymo-1.1-11-arm64-adhoc.zip` 和同名 `.sha256`。首次打包前会通过签名、Hardened Runtime、权限和包内容检查,ZIP 解压后再次检查。再次构建不覆盖已存在同名产物,可用 `--output` 另选目录。校验下载文件:
```bash
shasum -a 256 -c kymo-1.1-10-arm64-adhoc.zip.sha256
shasum -a 256 -c kymo-1.1-11-arm64-adhoc.zip.sha256
```
SHA-256 用于核对文件是否与发布者给出的文件一致,不等同于 Apple 身份认证;校验值应从可信渠道获取。
+1 -1
View File
@@ -345,6 +345,6 @@ DetailDemandChecks 验证概览零进程枚举、切页时旧同步任务不回
显式诊断构建(DEBUG 或 KYMO_AUDIT)可设置 KYMO_RESOURCE_AUDIT=1、KYMO_AUDIT_INTERACTIVE=1 打开固定面板供实际交互,可加 KYMO_AUDIT_SIZE=760x600 检查实际小 viewport;KYMO_AUDIT_PAGE=processes 选择资源循环中的进程页;KYMO_AUDIT_QUICK=1 使用 3 秒初始隐藏、每轮 30 秒展开 / 5 秒关闭,不执行暂停段。普通 Release 不包含驱动实现。此类诊断驱动不能替代实际输入事件,也不能证明长期性能预算。
TabPickerChecks 使用实际原生 Tab 检查双向选择绑定、三语标签原地更新及选择保留。640pt 面板与后续高度建议见[收窄方案](compact-panel-refinement-plan.md);卡片高度阶段新增独立列预算、动态窗口高度、0–128 核可读行数及小屏滚动回归;不复用上一轮资源数据宣称进一步节能。
TabPickerChecks 使用实际挂载的扁平页签检查双向选择绑定、原生点击 / 辅助功能按下、tabGroup / tabButton 角色及选中值、左右 / Home / End 切换和焦点跟随、三语标签原地更新及选择保留。外观是否存在玻璃高光仍需实际截图检查,程序语义检查不能替代视觉验收。640pt 面板与后续高度建议见[收窄方案](compact-panel-refinement-plan.md);卡片高度阶段新增独立列预算、动态窗口高度、0–128 核可读行数及小屏滚动回归;不复用上一轮资源数据宣称进一步节能。
卡片高度阶段的 PanelLayoutChecks 验证左 / 右卡片独立、常规 706pt 高度、无风扇收缩、高核心数 / 屏幕上限及滚动;PanelWindowChecks 验证控制器响应首选高度、重复预算不重设窗口与实际 contentLayoutRect;CPUCoreGridChecks 检查不再把高核心数挤进三行。实际设备只代表本机,纯几何检查不替代真实高核心数 / 多显示器验收。
+2 -2
View File
@@ -425,7 +425,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEAD_CODE_STRIPPING = YES;
ENABLE_APP_SANDBOX = YES;
ENABLE_OUTGOING_NETWORK_CONNECTIONS = YES;
@@ -458,7 +458,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEAD_CODE_STRIPPING = YES;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
@@ -23,6 +23,7 @@ struct AppearanceSettingsView: View {
NeutralTabPicker(title: "settings.title", selection: $selection,
options: [(.general, "settings.general"), (.about, "settings.about")])
}
.sharedBackgroundVisibility(.hidden)
}
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
requestID: presentation.requestID))
+161 -28
View File
@@ -1,51 +1,184 @@
import AppKit
import SwiftUI
/// Tab navigation uses AppKit's toolbar-style capsule in either hosting context.
/// Flat tab navigation shared by the panel and settings, independent of toolbar materials.
struct NeutralTabPicker<Selection: Hashable>: NSViewRepresentable {
let title: String
@Binding var selection: Selection
let options: [(Selection, String)]
@Environment(\.locale) private var locale
func makeCoordinator() -> NeutralTabPickerCoordinator { NeutralTabPickerCoordinator() }
func makeNSView(context: Context) -> FlatTabControl { FlatTabControl() }
func makeNSView(context: Context) -> NSSegmentedControl {
let control = NSSegmentedControl()
control.trackingMode = .selectOne
control.segmentStyle = .capsule
control.role = .tabs
control.borderShape = .capsule
control.segmentDistribution = .fillEqually
control.controlSize = .regular
control.target = context.coordinator
control.action = #selector(NeutralTabPickerCoordinator.changed(_:))
return control
}
func updateNSView(_ control: NSSegmentedControl, context: Context) {
if control.segmentCount != options.count { control.segmentCount = options.count }
for (index, option) in options.enumerated() {
let label = AppLocalization.string(option.1, locale: locale)
if control.label(forSegment: index) != label { control.setLabel(label, forSegment: index) }
}
let selected = options.firstIndex { $0.0 == selection } ?? -1
if control.selectedSegment != selected { control.selectedSegment = selected }
func updateNSView(_ control: FlatTabControl, context: Context) {
control.labels = options.map { AppLocalization.string($0.1, locale: locale) }
control.selectedIndex = options.firstIndex { $0.0 == selection } ?? -1
control.setAccessibilityLabel(AppLocalization.string(title, locale: locale))
let binding = $selection, values = options.map(\.0)
context.coordinator.onSelect = { index in
control.onSelect = { index in
guard values.indices.contains(index) else { return }
binding.wrappedValue = values[index]
}
}
func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSSegmentedControl, context: Context) -> CGSize? {
func sizeThatFits(_ proposal: ProposedViewSize, nsView: FlatTabControl, context: Context) -> CGSize? {
CGSize(width: proposal.width ?? nsView.intrinsicContentSize.width,
height: max(24, nsView.intrinsicContentSize.height))
height: proposal.height ?? nsView.intrinsicContentSize.height)
}
}
@MainActor final class NeutralTabPickerCoordinator: NSObject {
/// Native buttons retain press/focus behavior; drawing never invokes a system glass bezel.
@MainActor final class FlatTabControl: NSView {
var onSelect: ((Int) -> Void)?
@objc func changed(_ sender: NSSegmentedControl) { onSelect?(sender.selectedSegment) }
private(set) var buttons: [FlatTabButton] = []
var labels: [String] = [] {
didSet {
guard labels != oldValue else { return }
if buttons.count != labels.count {
buttons.forEach { $0.removeFromSuperview() }
buttons = labels.indices.map { index in
let button = FlatTabButton()
button.tag = index
button.target = self
button.action = #selector(pressed(_:))
addSubview(button)
return button
}
}
for (button, label) in zip(buttons, labels) { button.title = label }
updateSelection()
invalidateIntrinsicContentSize()
needsLayout = true
}
}
var selectedIndex = -1 {
didSet {
guard selectedIndex != oldValue else { return }
updateSelection()
NSAccessibility.post(element: self, notification: .valueChanged)
}
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
setAccessibilityElement(true)
setAccessibilityRole(.tabGroup)
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override var intrinsicContentSize: NSSize {
let labelWidth = labels.map { ($0 as NSString).size(withAttributes: [.font: NSFont.systemFont(ofSize: 12, weight: .medium)]).width }.max() ?? 0
return NSSize(width: CGFloat(labels.count) * (ceil(labelWidth) + 24) + CGFloat(max(0, labels.count - 1)) * 2 + 8, height: 32)
}
override func layout() {
super.layout()
guard !buttons.isEmpty else { return }
let width = max(0, (bounds.width - 8 - CGFloat(buttons.count - 1) * 2) / CGFloat(buttons.count))
for (index, button) in buttons.enumerated() {
button.frame = NSRect(x: 4 + CGFloat(index) * (width + 2), y: 4, width: width, height: max(0, bounds.height - 8))
}
}
override func draw(_ dirtyRect: NSRect) {
NSColor.labelColor.withAlphaComponent(0.04).setFill()
NSBezierPath(roundedRect: bounds, xRadius: bounds.height / 2, yRadius: bounds.height / 2).fill()
}
override func accessibilityChildren() -> [Any]? { buttons }
override func accessibilityTabs() -> [Any]? { buttons }
override func accessibilitySelectedChildren() -> [Any]? { buttons.filter(\.tabSelected) }
private func updateSelection() {
let hasFocus = buttons.contains { $0 === window?.firstResponder }
for (index, button) in buttons.enumerated() { button.tabSelected = index == selectedIndex }
if hasFocus, buttons.indices.contains(selectedIndex) { window?.makeFirstResponder(buttons[selectedIndex]) }
}
@objc private func pressed(_ sender: FlatTabButton) { select(sender.tag) }
fileprivate func select(_ index: Int) {
guard buttons.indices.contains(index), selectedIndex != index else { return }
selectedIndex = index
onSelect?(index)
}
}
@MainActor final class FlatTabButton: NSButton {
var tabSelected = false {
didSet { if tabSelected != oldValue { needsDisplay = true } }
}
private var hovered = false
private var hoverTracking: NSTrackingArea?
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
setButtonType(.momentaryChange)
isBordered = false
focusRingType = .exterior
setAccessibilityElement(true)
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override var acceptsFirstResponder: Bool { isEnabled }
override var canBecomeKeyView: Bool { isEnabled && tabSelected }
override func accessibilityRole() -> NSAccessibility.Role? { .radioButton }
override func accessibilitySubrole() -> NSAccessibility.Subrole? { .tabButtonSubrole }
override func accessibilityChildren() -> [Any]? { [] }
override func accessibilityValue() -> Any? { NSNumber(value: tabSelected) }
override func isAccessibilitySelected() -> Bool { tabSelected }
override func accessibilityPerformPress() -> Bool {
guard isEnabled else { return false }
performClick(nil)
return true
}
override func draw(_ dirtyRect: NSRect) {
let pressed = cell?.isHighlighted == true
NSColor.labelColor.withAlphaComponent(pressed ? 0.16 : (tabSelected ? 0.10 : (hovered ? 0.08 : 0))).setFill()
NSBezierPath(roundedRect: bounds, xRadius: bounds.height / 2, yRadius: bounds.height / 2).fill()
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
paragraph.lineBreakMode = .byTruncatingTail
let attributes: [NSAttributedString.Key: Any] = [
.font: NSFont.systemFont(ofSize: 12, weight: tabSelected ? .medium : .regular),
.foregroundColor: NSColor.labelColor,
.paragraphStyle: paragraph
]
let height = (title as NSString).size(withAttributes: attributes).height
(title as NSString).draw(in: NSRect(x: 4, y: (bounds.height - height) / 2, width: max(0, bounds.width - 8), height: height),
withAttributes: attributes)
}
override func drawFocusRingMask() {
NSBezierPath(roundedRect: bounds, xRadius: bounds.height / 2, yRadius: bounds.height / 2).fill()
}
override var focusRingMaskBounds: NSRect { bounds }
override func highlight(_ flag: Bool) { super.highlight(flag); needsDisplay = true }
override func updateTrackingAreas() {
super.updateTrackingAreas()
if let hoverTracking { removeTrackingArea(hoverTracking) }
let tracking = NSTrackingArea(rect: .zero, options: [.activeAlways, .inVisibleRect, .mouseEnteredAndExited], owner: self)
addTrackingArea(tracking)
hoverTracking = tracking
}
override func mouseEntered(with event: NSEvent) { hovered = true; needsDisplay = true }
override func mouseExited(with event: NSEvent) { hovered = false; needsDisplay = true }
override func keyDown(with event: NSEvent) {
guard let tabs = superview as? FlatTabControl,
event.modifierFlags.intersection([.command, .control, .option]).isEmpty else {
super.keyDown(with: event); return
}
let index: Int
switch event.keyCode {
case 123: index = max(0, tabs.selectedIndex - 1)
case 124: index = min(tabs.buttons.count - 1, tabs.selectedIndex + 1)
case 115: index = 0
case 119: index = tabs.buttons.count - 1
default: super.keyDown(with: event); return
}
tabs.select(index)
}
}
+36 -11
View File
@@ -13,7 +13,7 @@ private struct TabHost: View {
NeutralTabPicker(title: "panel.page", selection: $state.selected,
options: [(0, "panel.overview"), (1, "panel.processes")])
.environment(\.locale, state.locale)
.frame(width: 164, height: 28)
.frame(width: 164, height: 32)
}
}
@@ -31,21 +31,46 @@ private struct TabHost: View {
window.makeKeyAndOrderFront(nil)
await until { find(host) != nil }
let control = find(host)!
await until { control.label(forSegment: 0) == "Overview" }
precondition(control.selectedSegment == 0)
await until { control.buttons.first?.title == "Overview" }
precondition(control.selectedIndex == 0)
precondition(control.accessibilityRole() == .tabGroup)
precondition(control.accessibilityTabs()?.count == 2)
let first = control.buttons[0], second = control.buttons[1]
for button in [first, second] {
precondition(button.accessibilityRole() == .radioButton)
precondition(button.accessibilitySubrole() == .tabButtonSubrole)
precondition(button.isAccessibilityElement() && button.accessibilityChildren()?.isEmpty == true,
"Each tab must expose a single accessibility element")
}
precondition(first.isAccessibilitySelected() && !second.isAccessibilitySelected())
precondition(first.canBecomeKeyView && !second.canBecomeKeyView)
state.selected = 1
await until { control.selectedSegment == 1 }
control.selectedSegment = 0
_ = control.sendAction(control.action, to: control.target)
await until { control.selectedIndex == 1 }
precondition(second.isAccessibilitySelected() && !first.isAccessibilitySelected())
precondition((second.accessibilityValue() as? NSNumber)?.boolValue == true)
precondition(control.accessibilitySelectedChildren()?.first as? NSButton === second)
first.performClick(nil)
await until { state.selected == 0 }
precondition(second.accessibilityPerformPress())
await until { state.selected == 1 }
precondition(window.makeFirstResponder(second))
for (code, selected) in [(UInt16(123), 0), (124, 1), (124, 1), (115, 0), (119, 1)] {
let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [], timestamp: 0,
windowNumber: window.windowNumber, context: nil, characters: "",
charactersIgnoringModifiers: "", isARepeat: false, keyCode: code)!
window.sendEvent(event)
await until { state.selected == selected }
precondition(window.firstResponder === control.buttons[selected], "Arrow navigation must retain focus on the selected tab")
}
for (locale, title) in [("zh-Hans", "概览"), ("zh-Hant", "概覽"), ("en", "Overview")] {
state.locale = Locale(identifier: locale)
await until { control.label(forSegment: 0) == title }
await until { control.buttons[0].title == title }
precondition(find(host) === control, "Locale updates must retain the mounted native control")
precondition(control.selectedSegment == 0)
precondition(control.buttons[0] === first && control.buttons[1] === second)
precondition(control.selectedIndex == 1)
}
window.orderOut(nil); window.close()
print("PASS: native tab binding in both directions, localized labels in place and retained selection")
print("PASS: flat tab binding, native/AX press, tab roles and selection, arrow/Home/End focus navigation and in-place three-language updates")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
@@ -57,8 +82,8 @@ private struct TabHost: View {
precondition(condition(), "Timed out waiting for native tab update")
}
@MainActor private static func find(_ view: NSView) -> NSSegmentedControl? {
if let control = view as? NSSegmentedControl { return control }
@MainActor private static func find(_ view: NSView) -> FlatTabControl? {
if let control = view as? FlatTabControl { return control }
return view.subviews.lazy.compactMap { find($0) }.first
}
}