diff --git a/Easydict/App/Assets.xcassets/service_cell_highlight.colorset/Contents.json b/Easydict/App/Assets.xcassets/service_cell_highlight.colorset/Contents.json new file mode 100644 index 000000000..f6b481345 --- /dev/null +++ b/Easydict/App/Assets.xcassets/service_cell_highlight.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "0.847", + "red" : "0.706" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.251", + "green" : "0.251", + "red" : "0.251" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Easydict/NewApp/View/ServiceItemView.swift b/Easydict/NewApp/View/ServiceItemView.swift index 9f34a1740..d21f17e98 100644 --- a/Easydict/NewApp/View/ServiceItemView.swift +++ b/Easydict/NewApp/View/ServiceItemView.swift @@ -8,6 +8,7 @@ import SwiftUI +@available(macOS 13.0, *) struct ServiceItemView: View { @Binding var service: QueryService @@ -27,14 +28,14 @@ struct ServiceItemView: View { .toggleStyle(.switch) .controlSize(.small) } - .padding(4.0) } } +@available(macOS 13, *) #Preview { - let service = EZLocalStorage.shared().allServices(.mini).first - return ServiceItemView(service: .constant(service ?? QueryService())) { val in + let service = EZLocalStorage.shared().allServices(.mini).first ?? QueryService() + return ServiceItemView(service: .constant(service)) { val in print("toggle value changed: \(val)") } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift index 96fd368a9..2cb904369 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift @@ -8,18 +8,12 @@ import SwiftUI -enum ServiceWindowType: Int { - case mini - case fixed - case main -} - +@available(macOS 13, *) struct ServiceTab: View { @State private var windowTypeValue = EZWindowType.mini.rawValue - @State private var serviceTypes: [ServiceType] = [] - @State private var services: [QueryService] = [] + @State private var selectedIndex: Int? var segmentCtrl: some View { Picker("", selection: $windowTypeValue) { @@ -47,13 +41,24 @@ struct ServiceTab: View { ) { isEnable in serviceToggled(index: index, isEnable: isEnable) } + .tag(index) + .contentShape(Rectangle()) + .onTapGesture { + if selectedIndex == nil || selectedIndex != index { + selectedIndex = index + } else { + selectedIndex = nil + } + } + .listRowBackground(selectedIndex == index ? Color("service_cell_highlight") : Color.clear) } .onMove(perform: { indices, newOffset in onServiceItemMove(fromOffsets: indices, toOffset: newOffset) }) + .listRowSeparator(.hidden) } - .listStyle(.inset) - .clipShape(RoundedRectangle(cornerRadius: 10.0)) + .listStyle(.plain) + .clipShape(RoundedRectangle(cornerRadius: 8.0)) .padding([.horizontal, .bottom]) } @@ -124,6 +129,7 @@ struct ServiceTab: View { } } +@available(macOS 13, *) #Preview { ServiceTab() }