diff --git a/ShhShell/Host/Host.swift b/ShhShell/Host/Host.swift index 84f3392..9cc88e4 100644 --- a/ShhShell/Host/Host.swift +++ b/ShhShell/Host/Host.swift @@ -8,7 +8,7 @@ import Foundation import SwiftUI -protocol HostPr: Codable, Identifiable, Equatable { +protocol HostPr: Codable, Identifiable, Equatable, Hashable { var id: UUID { get set } var name: String { get set } var symbol: Symbol { get set } diff --git a/ShhShell/Host/SymbolPreview.swift b/ShhShell/Host/SymbolPreview.swift index a5312db..f545a21 100644 --- a/ShhShell/Host/SymbolPreview.swift +++ b/ShhShell/Host/SymbolPreview.swift @@ -8,28 +8,29 @@ import SwiftUI struct SymbolPreview: View { - @State var host: Host + @State var symbol: Symbol + @State var label: String var body: some View { ZStack(alignment: .center) { - if host.symbol.isCustom { - Image(host.symbol.sf) + if symbol.isCustom { + Image(symbol.sf) .resizable().scaledToFit() .symbolRenderingMode(.monochrome) .padding(5) } else { - Image(systemName: host.symbol.sf) + Image(systemName: symbol.sf) .resizable().scaledToFit() .symbolRenderingMode(.monochrome) .padding(5) } - Text(host.label) + Text(label) .font(.headline) - .offset(host.symbol.offset) + .offset(symbol.offset) } } } #Preview { - SymbolPreview(host: Host.debug) + SymbolPreview(symbol: Symbol.desktopcomputer, label: "lo0") } diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index 8c0bda9..62c5405 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -25,26 +25,28 @@ struct ConnectionView: View { NavigationStack { List { Section { - HStack { - Picker("", selection: $handler.host.symbol) { + ScrollView(.horizontal) { + HStack { ForEach(Symbol.allCases, id: \.self) { symbol in - Group { - if symbol.isCustom { - Image(symbol.sf) - .resizable().scaledToFit() - } else { - Image(systemName: symbol.sf) - .resizable().scaledToFit() + ZStack { + if handler.host.symbol == symbol { + RoundedRectangle(cornerRadius: 10) + .fill(.gray.opacity(0.5)) } + SymbolPreview(symbol: symbol, label: handler.host.label) + .padding(5) + } + .frame(width: 60, height: 60) + .onTapGesture { + withAnimation { handler.host.symbol = symbol } } - .padding(5) - .tag(symbol) } } - .controlSize(.large) - .pickerStyle(SegmentedPickerStyle()) - - SymbolPreview(host: handler.host) + } + + HStack { + SymbolPreview(symbol: handler.host.symbol, label: handler.host.label) + .id(handler.host) .frame(width: 60, height: 60) TextField("label", text: $handler.host.label) @@ -60,7 +62,7 @@ struct ConnectionView: View { .modifier(foregroundColorStyle(checkAuth(handler.state) ? .green : .red)) Text("\(handler.state)") } - + TextField("name", text: $handler.host.name) .textFieldStyle(.roundedBorder) diff --git a/ShhShell/Views/Hosts/HostsView.swift b/ShhShell/Views/Hosts/HostsView.swift index d2f7ca5..eafde56 100644 --- a/ShhShell/Views/Hosts/HostsView.swift +++ b/ShhShell/Views/Hosts/HostsView.swift @@ -44,7 +44,7 @@ struct HostsView: View { keyManager: keyManager ) } label: { - SymbolPreview(host: host) + SymbolPreview(symbol: host.symbol, label: host.label) .frame(width: 40, height: 40) Text(hostsManager.makeLabel(forHost: host)) }