Fix situations where Clash mode is too long
This commit is contained in:
@@ -14,19 +14,7 @@ public struct ClashModeCard: View {
|
|||||||
DashboardCardView(title: "", isHalfWidth: false) {
|
DashboardCardView(title: "", isHalfWidth: false) {
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
DashboardCardHeader(icon: "circle.grid.2x2.fill", title: "Mode")
|
DashboardCardHeader(icon: "circle.grid.2x2.fill", title: "Mode")
|
||||||
Picker("", selection: Binding(get: {
|
modeMenu
|
||||||
clashMode
|
|
||||||
}, set: { newMode in
|
|
||||||
clashMode = newMode
|
|
||||||
Task {
|
|
||||||
await setClashMode(newMode)
|
|
||||||
}
|
|
||||||
})) {
|
|
||||||
ForEach(commandClient.clashModeList, id: \.self) { mode in
|
|
||||||
Text(mode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(.segmented)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@@ -39,6 +27,69 @@ public struct ClashModeCard: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var modeMenu: some View {
|
||||||
|
Menu {
|
||||||
|
ForEach(commandClient.clashModeList, id: \.self) { mode in
|
||||||
|
Button {
|
||||||
|
clashMode = mode
|
||||||
|
Task {
|
||||||
|
await setClashMode(mode)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
if mode == clashMode {
|
||||||
|
Label(mode, systemImage: "checkmark")
|
||||||
|
} else {
|
||||||
|
Text(mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
Text(clashMode)
|
||||||
|
.font(.system(size: buttonFontSize, weight: .medium))
|
||||||
|
.foregroundStyle(.primary)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Image(systemName: "chevron.up.chevron.down")
|
||||||
|
.font(.system(size: chevronSize, weight: .semibold))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 14)
|
||||||
|
.frame(height: buttonHeight)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.selectorBackground()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var buttonHeight: CGFloat {
|
||||||
|
#if os(tvOS)
|
||||||
|
60
|
||||||
|
#elseif os(macOS)
|
||||||
|
32
|
||||||
|
#else
|
||||||
|
44
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private var buttonFontSize: CGFloat {
|
||||||
|
#if os(macOS)
|
||||||
|
13
|
||||||
|
#else
|
||||||
|
17
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private var chevronSize: CGFloat {
|
||||||
|
#if os(macOS)
|
||||||
|
10
|
||||||
|
#else
|
||||||
|
12
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private var shouldShowPicker: Bool {
|
private var shouldShowPicker: Bool {
|
||||||
commandClient.clashModeList.count > 1
|
commandClient.clashModeList.count > 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ struct ProfileSelectorButton: View {
|
|||||||
|
|
||||||
// MARK: - View Extension
|
// MARK: - View Extension
|
||||||
|
|
||||||
private extension View {
|
extension View {
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func selectorBackground() -> some View {
|
func selectorBackground() -> some View {
|
||||||
if #available(iOS 26.0, macOS 26.0, tvOS 26.0, *) {
|
if #available(iOS 26.0, macOS 26.0, tvOS 26.0, *) {
|
||||||
|
|||||||
Reference in New Issue
Block a user