Improve filtering UI

This commit is contained in:
LiYanan2004 2025-09-02 14:40:35 +08:00
parent 4ccb6e7f06
commit cdf3675a5e
3 changed files with 52 additions and 62 deletions

View file

@ -35,21 +35,18 @@ struct PlatformsView: View {
.frame(maxWidth: .infinity, alignment: .leading)
if !architectures.isEmpty {
Spacer()
Button {
switch selectedRuntimeArchitecture {
case .arm64: selectedRuntimeArchitecture = .x86_64
case .x86_64: selectedRuntimeArchitecture = .arm64
}
} label: {
switch selectedRuntimeArchitecture {
case .arm64:
Label(selectedRuntimeArchitecture.displayString, systemImage: "m4.button.horizontal")
.labelStyle(.trailingIcon)
case .x86_64:
Label(selectedRuntimeArchitecture.displayString, systemImage: "cpu.fill")
.labelStyle(.trailingIcon)
Picker("Architecture", selection: $selectedRuntimeArchitecture) {
ForEach(Architecture.allCases, id: \.self) { arch in
Label(arch.displayString, systemImage: arch.iconName)
.tag(arch)
}
.labelStyle(.trailingIcon)
}
.pickerStyle(.menu)
.menuStyle(.button)
.buttonStyle(.borderless)
.fixedSize()
.labelsHidden()
}
}

View file

@ -22,60 +22,44 @@ struct MainToolbarModifier: ViewModifier {
}
.keyboardShortcut(KeyEquivalent("r"))
.help("RefreshDescription")
Spacer()
Button(action: {
switch architectures {
case .universal: architectures = .appleSilicon
case .appleSilicon: architectures = .universal
}
}) {
switch architectures {
case .universal:
Label("Universal", systemImage: "cpu.fill")
case .appleSilicon:
Label("Apple Silicon", systemImage: "m4.button.horizontal")
.labelStyle(.trailingIcon)
.foregroundColor(.accentColor)
}
}
.help("FilterAvailableDescription")
.disabled(architectures.isManaged)
Button(action: {
switch category {
case .all: category = .release
case .release: category = .beta
case .beta: category = .all
Spacer()
let isFiltering = isInstalledOnly || category != .all || architectures != .universal
Menu("Filter", systemImage: "line.horizontal.3.decrease.circle") {
Section {
Toggle("Installed Only", isOn: $isInstalledOnly)
}
}) {
switch category {
case .all:
Label("All", systemImage: "line.horizontal.3.decrease.circle")
case .release:
.help("FilterInstalledDescription")
Section {
Picker("Category", selection: $category) {
Label("All", systemImage: "line.horizontal.3.decrease.circle")
.tag(XcodeListCategory.all)
Label("ReleaseOnly", systemImage: "line.horizontal.3.decrease.circle.fill")
.labelStyle(.trailingIcon)
.tag(XcodeListCategory.release)
Label("BetaOnly", systemImage: "line.horizontal.3.decrease.circle.fill")
.tag(XcodeListCategory.beta)
}
}
.help("FilterAvailableDescription")
.disabled(category.isManaged)
Section {
Picker("Architecture", selection: $architectures) {
Label("Universal", systemImage: "cpu.fill")
.tag(XcodeListArchitecture.universal)
Label("Apple Silicon", systemImage: "m4.button.horizontal")
.foregroundColor(.accentColor)
case .beta:
Label("BetaOnly", systemImage: "line.horizontal.3.decrease.circle.fill")
.labelStyle(.trailingIcon)
.foregroundColor(.accentColor)
.tag(XcodeListArchitecture.appleSilicon)
}
.help("FilterArchitecturesDescription")
.disabled(architectures.isManaged)
}
.labelStyle(.trailingIcon)
}
.help("FilterAvailableDescription")
.disabled(category.isManaged)
Button(action: {
isInstalledOnly.toggle()
}) {
if isInstalledOnly {
Label("Filter", systemImage: "arrow.down.app.fill")
.foregroundColor(.accentColor)
} else {
Label("Filter", systemImage: "arrow.down.app")
}
}
.help("FilterInstalledDescription")
.pickerStyle(.inline)
.symbolVariant(isFiltering ? .fill : .none)
}
}
}

View file

@ -8,7 +8,7 @@
import Foundation
/// The name of an Architecture.
public enum Architecture: String, Codable, Equatable, Hashable, Identifiable {
public enum Architecture: String, Codable, Equatable, Hashable, Identifiable, CaseIterable {
public var id: Self { self }
/// The Arm64 architecture (Apple Silicon)
@ -24,6 +24,15 @@ public enum Architecture: String, Codable, Equatable, Hashable, Identifiable {
return "Intel"
}
}
public var iconName: String {
switch self {
case .arm64:
return "m4.button.horizontal"
case .x86_64:
return "cpu.fill"
}
}
}
extension Array where Element == Architecture {