refactor(ui): 统一胶囊页签并将面板收窄至640点

This commit is contained in:
2026-11-08 15:06:27 +08:00
parent 48f7ac73c0
commit 521319ef93
18 changed files with 223 additions and 26 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ import CoreGraphics
@main struct PanelLayoutChecks {
static func main() {
precondition(PanelLayout.contentSize(visible: CGRect(x: 0, y: 0, width: 1512, height: 900)).width == 640)
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)
@@ -13,7 +14,7 @@ import CoreGraphics
precondition(visible.insetBy(dx: 16, dy: 16).contains(centered))
}
}
for width: CGFloat in [640, 679, 680, 899, 900, 960] {
for width: CGFloat in [480, 559, 560, 600, 640, 960] {
let size = CGSize(width: width, height: 820)
let columns = PanelLayout.columns(width: width)
let cardWidth = PanelLayout.cardWidth(size: size)
@@ -28,7 +29,7 @@ import CoreGraphics
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: width, height: 2400), rows: rows))
}
precondition(PanelLayout.rowHeights(columns: 2, coreRows: 2, fanCount: 0) == [220, 204, 260])
precondition(PanelLayout.columns(width: 960) == 2 && PanelLayout.columns(width: 679) == 1)
precondition(PanelLayout.columns(width: 960) == 2 && PanelLayout.columns(width: 559) == 1 && PanelLayout.columns(width: 640) == 2)
precondition(!PanelLayout.needsResourceScroll(size: CGSize(width: 960, height: 800), rows: [220, 204, 260]))
let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in
let id = ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0)
+64
View File
@@ -0,0 +1,64 @@
import AppKit
import SwiftUI
import Observation
@MainActor @Observable private final class TabState {
var selected = 0
var locale = Locale(identifier: "en")
}
private struct TabHost: View {
@Bindable var state: TabState
var body: some View {
NeutralTabPicker(title: "panel.page", selection: $state.selected,
options: [(0, "panel.overview"), (1, "panel.processes")])
.environment(\.locale, state.locale)
.frame(width: 164, height: 28)
}
}
@main struct TabPickerChecks {
@MainActor static func main() {
_ = NSApplication.shared
NSApp.setActivationPolicy(.accessory)
Task { @MainActor in
let state = TabState()
let window = NSWindow(contentRect: NSRect(x: 40, y: 40, width: 220, height: 70),
styleMask: [.titled], backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
let host = NSHostingView(rootView: TabHost(state: state))
window.contentView = host
window.makeKeyAndOrderFront(nil)
await until { find(host) != nil }
let control = find(host)!
await until { control.label(forSegment: 0) == "Overview" }
precondition(control.selectedSegment == 0)
state.selected = 1
await until { control.selectedSegment == 1 }
control.selectedSegment = 0
_ = control.sendAction(control.action, to: control.target)
await until { state.selected == 0 }
for (locale, title) in [("zh-Hans", "概览"), ("zh-Hant", "概覽"), ("en", "Overview")] {
state.locale = Locale(identifier: locale)
await until { control.label(forSegment: 0) == title }
precondition(find(host) === control, "Locale updates must retain the mounted native control")
precondition(control.selectedSegment == 0)
}
window.orderOut(nil); window.close()
print("PASS: native tab binding in both directions, localized labels in place and retained selection")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
}
@MainActor private static func until(_ condition: () -> Bool) async {
let deadline = ContinuousClock.now.advanced(by: .seconds(3))
while !condition() && ContinuousClock.now < deadline { try? await Task.sleep(for: .milliseconds(20)) }
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 }
return view.subviews.lazy.compactMap { find($0) }.first
}
}