refactor(ui): 统一胶囊页签并将面板收窄至640点
This commit is contained in:
@@ -58,6 +58,7 @@ extension MenuPanelView {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Text(verbatim: address ?? "--").font(PanelStyle.value).monospacedDigit().textSelection(.enabled)
|
||||
.help(Text(verbatim: address ?? "--"))
|
||||
Spacer(minLength: 0)
|
||||
if let address {
|
||||
Button {
|
||||
|
||||
@@ -88,7 +88,8 @@ extension MenuPanelView {
|
||||
thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1),
|
||||
scaleLabel: MetricFormat.memory(snapshot.memory?.total), firstValueFormat: .memory, firstLabel: "gpu.totalUtilization",
|
||||
secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals,
|
||||
showsLegendValues: cardContentWidth >= 340)
|
||||
if let memory = snapshot.memory {
|
||||
MemoryDetailsView(memory: memory)
|
||||
} else {
|
||||
@@ -184,7 +185,8 @@ extension MenuPanelView {
|
||||
Text("battery.timeEstimate").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
if battery.externalPower {
|
||||
Text("battery.timeNotApplicable").font(PanelStyle.value)
|
||||
Text("battery.notApplicableShort").font(PanelStyle.value)
|
||||
.help(Text("battery.timeNotApplicable"))
|
||||
} else if let minutes = battery.minutesRemaining {
|
||||
MetricText(value: "\(minutes) min").font(PanelStyle.value)
|
||||
} else {
|
||||
|
||||
@@ -124,11 +124,9 @@ struct MenuPanelView: View {
|
||||
}
|
||||
|
||||
private var pagePicker: some View {
|
||||
Picker("panel.page", selection: Binding(get: { presentation.page }, set: { presentation.page = $0 })) {
|
||||
Text("panel.overview").tag(PanelPage.overview)
|
||||
Text("panel.processes").tag(PanelPage.processes)
|
||||
}
|
||||
.pickerStyle(.segmented).labelsHidden().frame(width: 164)
|
||||
NeutralTabPicker(title: "panel.page", selection: Binding(get: { presentation.page }, set: { presentation.page = $0 }),
|
||||
options: [(.overview, "panel.overview"), (.processes, "panel.processes")])
|
||||
.frame(width: 164)
|
||||
.accessibilityIdentifier("panel.tabs")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import CoreGraphics
|
||||
nonisolated enum PanelLayout {
|
||||
static let baseCardHeight: CGFloat = 204
|
||||
static func headerHeight(width: CGFloat) -> CGFloat { width >= 840 ? 32 : 64 }
|
||||
static func columns(width: CGFloat) -> Int { width >= 680 ? 2 : 1 }
|
||||
static func columns(width: CGFloat) -> Int { width >= 560 ? 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))
|
||||
@@ -28,7 +28,7 @@ nonisolated enum PanelLayout {
|
||||
}
|
||||
|
||||
static func contentSize(visible: CGRect, chrome: CGSize = .zero) -> CGSize {
|
||||
CGSize(width: max(1, min(960, visible.width - 32 - max(0, chrome.width))),
|
||||
CGSize(width: max(1, min(640, visible.width - 32 - max(0, chrome.width))),
|
||||
height: max(1, min(800, visible.height - 32 - max(0, chrome.height))))
|
||||
}
|
||||
static func centeredFrame(_ frame: CGRect, visible: CGRect) -> CGRect {
|
||||
|
||||
@@ -20,12 +20,8 @@ struct AppearanceSettingsView: View {
|
||||
.padding(12)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .principal) {
|
||||
Picker("settings.title", selection: $selection) {
|
||||
Text("settings.general").tag(SettingsPage.general)
|
||||
Text("settings.about").tag(SettingsPage.about)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
NeutralTabPicker(title: "settings.title", selection: $selection,
|
||||
options: [(.general, "settings.general"), (.about, "settings.about")])
|
||||
}
|
||||
}
|
||||
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
{
|
||||
"sourceLanguage" : "en",
|
||||
"strings" : {
|
||||
"battery.notApplicableShort" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "N/A"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "不适用"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "不適用"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"panel.power" : {
|
||||
"localizations" : {
|
||||
"zh-Hans" : {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Tab navigation uses AppKit's toolbar-style capsule in either hosting context.
|
||||
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) -> 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 }
|
||||
control.setAccessibilityLabel(AppLocalization.string(title, locale: locale))
|
||||
let binding = $selection, values = options.map(\.0)
|
||||
context.coordinator.onSelect = { index in
|
||||
guard values.indices.contains(index) else { return }
|
||||
binding.wrappedValue = values[index]
|
||||
}
|
||||
}
|
||||
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSSegmentedControl, context: Context) -> CGSize? {
|
||||
CGSize(width: proposal.width ?? nsView.intrinsicContentSize.width,
|
||||
height: max(24, nsView.intrinsicContentSize.height))
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor final class NeutralTabPickerCoordinator: NSObject {
|
||||
var onSelect: ((Int) -> Void)?
|
||||
@objc func changed(_ sender: NSSegmentedControl) { onSelect?(sender.selectedSegment) }
|
||||
}
|
||||
@@ -28,6 +28,7 @@ struct CardField<Content: View>: View {
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title).font(PanelStyle.label).foregroundStyle(.secondary).frame(height: 14)
|
||||
.help(Text(title))
|
||||
content().font(PanelStyle.value).monospacedDigit().frame(height: 14)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Reference in New Issue
Block a user