fix picker but making it a cusotm one

fix symbol preview not updating
undo change to simplify symbolpreview
add hashable to host
This commit is contained in:
neon443
2025-06-26 10:16:53 +01:00
parent 58596905d7
commit 5e0908206c
4 changed files with 28 additions and 25 deletions

View File

@@ -8,7 +8,7 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
protocol HostPr: Codable, Identifiable, Equatable { protocol HostPr: Codable, Identifiable, Equatable, Hashable {
var id: UUID { get set } var id: UUID { get set }
var name: String { get set } var name: String { get set }
var symbol: Symbol { get set } var symbol: Symbol { get set }

View File

@@ -8,28 +8,29 @@
import SwiftUI import SwiftUI
struct SymbolPreview: View { struct SymbolPreview: View {
@State var host: Host @State var symbol: Symbol
@State var label: String
var body: some View { var body: some View {
ZStack(alignment: .center) { ZStack(alignment: .center) {
if host.symbol.isCustom { if symbol.isCustom {
Image(host.symbol.sf) Image(symbol.sf)
.resizable().scaledToFit() .resizable().scaledToFit()
.symbolRenderingMode(.monochrome) .symbolRenderingMode(.monochrome)
.padding(5) .padding(5)
} else { } else {
Image(systemName: host.symbol.sf) Image(systemName: symbol.sf)
.resizable().scaledToFit() .resizable().scaledToFit()
.symbolRenderingMode(.monochrome) .symbolRenderingMode(.monochrome)
.padding(5) .padding(5)
} }
Text(host.label) Text(label)
.font(.headline) .font(.headline)
.offset(host.symbol.offset) .offset(symbol.offset)
} }
} }
} }
#Preview { #Preview {
SymbolPreview(host: Host.debug) SymbolPreview(symbol: Symbol.desktopcomputer, label: "lo0")
} }

View File

@@ -25,26 +25,28 @@ struct ConnectionView: View {
NavigationStack { NavigationStack {
List { List {
Section { Section {
HStack { ScrollView(.horizontal) {
Picker("", selection: $handler.host.symbol) { HStack {
ForEach(Symbol.allCases, id: \.self) { symbol in ForEach(Symbol.allCases, id: \.self) { symbol in
Group { ZStack {
if symbol.isCustom { if handler.host.symbol == symbol {
Image(symbol.sf) RoundedRectangle(cornerRadius: 10)
.resizable().scaledToFit() .fill(.gray.opacity(0.5))
} else {
Image(systemName: symbol.sf)
.resizable().scaledToFit()
} }
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())
HStack {
SymbolPreview(host: handler.host) SymbolPreview(symbol: handler.host.symbol, label: handler.host.label)
.id(handler.host)
.frame(width: 60, height: 60) .frame(width: 60, height: 60)
TextField("label", text: $handler.host.label) TextField("label", text: $handler.host.label)
@@ -60,7 +62,7 @@ struct ConnectionView: View {
.modifier(foregroundColorStyle(checkAuth(handler.state) ? .green : .red)) .modifier(foregroundColorStyle(checkAuth(handler.state) ? .green : .red))
Text("\(handler.state)") Text("\(handler.state)")
} }
TextField("name", text: $handler.host.name) TextField("name", text: $handler.host.name)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)

View File

@@ -44,7 +44,7 @@ struct HostsView: View {
keyManager: keyManager keyManager: keyManager
) )
} label: { } label: {
SymbolPreview(host: host) SymbolPreview(symbol: host.symbol, label: host.label)
.frame(width: 40, height: 40) .frame(width: 40, height: 40)
Text(hostsManager.makeLabel(forHost: host)) Text(hostsManager.makeLabel(forHost: host))
} }