refactor(settings): 改用常规关于选项卡并统一蓝色强调色
This commit is contained in:
@@ -8,96 +8,30 @@ struct AppearanceSettingsView: View {
|
||||
@Bindable var sampling: SamplingPreferences
|
||||
let presentation: SettingsPresentation
|
||||
@Environment(\.locale) private var locale
|
||||
@State private var colorPicker = CustomColorPicker()
|
||||
@State private var selection: SettingsPage? = .appearance
|
||||
@State private var selection = SettingsPage.general
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
List(selection: $selection) {
|
||||
ForEach(SettingsPage.allCases) { page in
|
||||
Label(page.title, systemImage: page.symbol).tag(page)
|
||||
}
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
.navigationSplitViewColumnWidth(min: 180, ideal: 205, max: 240)
|
||||
} detail: {
|
||||
Group {
|
||||
switch selectedPage {
|
||||
case .appearance: appearancePage
|
||||
case .language: languagePage
|
||||
case .monitoring: monitoringPage
|
||||
case .about: aboutPage
|
||||
}
|
||||
}
|
||||
.navigationTitle(selectedPage.title)
|
||||
TabView(selection: $selection) {
|
||||
generalPage
|
||||
.tabItem { Label("settings.general", systemImage: "gearshape") }
|
||||
.tag(SettingsPage.general)
|
||||
aboutPage
|
||||
.tabItem { Label("settings.about", systemImage: "info.circle") }
|
||||
.tag(SettingsPage.about)
|
||||
}
|
||||
.navigationSplitViewStyle(.balanced)
|
||||
.padding(12)
|
||||
.background(SettingsWindowLifecycle(title: AppLocalization.string("settings.title", locale: locale),
|
||||
requestID: presentation.requestID,
|
||||
onClose: { colorPicker.close() }))
|
||||
.onChange(of: preferences.accent) { _, choice in
|
||||
if choice == .custom {
|
||||
Task { @MainActor in
|
||||
await Task.yield()
|
||||
guard preferences.accent == .custom else { return }
|
||||
colorPicker.show(for: preferences)
|
||||
}
|
||||
} else { colorPicker.close() }
|
||||
}
|
||||
.onChange(of: selection) { _, _ in colorPicker.close() }
|
||||
.frame(minWidth: 720, idealWidth: 780, minHeight: 460, idealHeight: 540)
|
||||
requestID: presentation.requestID))
|
||||
.frame(minWidth: 600, idealWidth: 640, minHeight: 420, idealHeight: 460)
|
||||
.modifier(AppearanceStyle(preferences: preferences, refreshContentOnChange: true))
|
||||
}
|
||||
|
||||
private var selectedPage: SettingsPage { selection ?? .appearance }
|
||||
|
||||
private var appearancePage: some View {
|
||||
private var generalPage: some View {
|
||||
Form {
|
||||
Section {
|
||||
LabeledContent("appearance.title") {
|
||||
LiquidAppearancePicker(selection: $preferences.appearance)
|
||||
}
|
||||
LabeledContent("accent.title") {
|
||||
Picker("accent.title", selection: $preferences.accent) {
|
||||
Text("accent.system").tag(AccentChoice.system)
|
||||
Text("accent.blue").tag(AccentChoice.blue)
|
||||
Text("accent.purple").tag(AccentChoice.purple)
|
||||
Text("accent.teal").tag(AccentChoice.teal)
|
||||
Text("accent.green").tag(AccentChoice.green)
|
||||
Text("accent.orange").tag(AccentChoice.orange)
|
||||
Text("accent.pink").tag(AccentChoice.pink)
|
||||
Text("accent.custom").tag(AccentChoice.custom)
|
||||
}
|
||||
.labelsHidden()
|
||||
.fixedSize()
|
||||
}
|
||||
if preferences.accent == .custom {
|
||||
LabeledContent("accent.custom") {
|
||||
CustomColorWell(preferences: preferences, picker: colorPicker)
|
||||
.frame(width: 44, height: 26)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.top, 6)
|
||||
}
|
||||
|
||||
private var monitoringPage: some View {
|
||||
Form {
|
||||
Section {
|
||||
LabeledContent("sampling.background") {
|
||||
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
|
||||
}
|
||||
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
|
||||
}
|
||||
}.formStyle(.grouped).padding(.horizontal, 12).padding(.top, 6)
|
||||
}
|
||||
|
||||
private var languagePage: some View {
|
||||
Form {
|
||||
Section {
|
||||
LabeledContent("language.title") {
|
||||
Picker("language.title", selection: $language.language) {
|
||||
Text("language.system").tag(AppLanguage.system)
|
||||
@@ -108,14 +42,15 @@ struct AppearanceSettingsView: View {
|
||||
.labelsHidden()
|
||||
.fixedSize()
|
||||
}
|
||||
Text("language.immediate")
|
||||
.font(.callout)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Section {
|
||||
LabeledContent("sampling.background") {
|
||||
IntervalControl(milliseconds: $sampling.backgroundMilliseconds)
|
||||
}
|
||||
Text("sampling.backgroundHelp").font(.callout).foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.top, 6)
|
||||
}
|
||||
|
||||
private var aboutPage: some View {
|
||||
@@ -164,7 +99,7 @@ private struct LiquidAppearancePicker: View {
|
||||
HStack(spacing: 4) {
|
||||
ForEach(AppAppearance.allCases) { appearance in
|
||||
Button {
|
||||
// Theme changes must not animate the native split view / Form hierarchy.
|
||||
// Theme changes must not animate the native tab view / Form hierarchy.
|
||||
selection = appearance
|
||||
} label: {
|
||||
Label(appearance.title, systemImage: appearance.symbol)
|
||||
@@ -215,23 +150,6 @@ private extension AppAppearance {
|
||||
}
|
||||
}
|
||||
|
||||
private enum SettingsPage: String, CaseIterable, Identifiable {
|
||||
case appearance, language, monitoring, about
|
||||
var id: String { rawValue }
|
||||
var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .appearance: "settings.appearance"
|
||||
case .language: "settings.language"
|
||||
case .monitoring: "settings.monitoring"
|
||||
case .about: "settings.about"
|
||||
}
|
||||
}
|
||||
var symbol: String {
|
||||
switch self {
|
||||
case .appearance: "paintpalette"
|
||||
case .language: "globe"
|
||||
case .monitoring: "timer"
|
||||
case .about: "info.circle"
|
||||
}
|
||||
}
|
||||
private enum SettingsPage: Hashable {
|
||||
case general, about
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user