added textbox to make pretty textboxes with label

updated connectionview to use nice textboxes with labels
put disconnect and minimize on the left
This commit is contained in:
neon443
2025-06-30 13:52:24 +01:00
parent 9c32778d01
commit 24bf52ff16
4 changed files with 54 additions and 29 deletions

View File

@@ -51,43 +51,34 @@ struct ConnectionView: View {
.id(handler.host)
.frame(width: 60, height: 60)
TextField("label", text: $handler.host.label)
.textFieldStyle(.roundedBorder)
TextBox(label: "Icon Text", text: $handler.host.label)
}
}
Section {
Text("\(handler.state)")
.foregroundStyle(handler.state.color)
TextField("name", text: $handler.host.name)
.textFieldStyle(.roundedBorder)
TextBox(label: "Name", text: $handler.host.name)
TextField("address", text: $handler.host.address)
.textFieldStyle(.roundedBorder)
TextBox(label: "Address", text: $handler.host.address)
TextField(
"port",
text: Binding(
TextBox(label: "Port", text: Binding(
get: { String(handler.host.port) },
set: {
if let input = Int($0) {
handler.host.port = input
}
}
)
}),
keyboardType: .numberPad
)
.keyboardType(.numberPad)
.textFieldStyle(.roundedBorder)
}
Section {
TextField("Username", text: $handler.host.username)
.textFieldStyle(.roundedBorder)
TextBox(label: "Username", text: $handler.host.username)
SecureField("Password", text: $handler.host.password)
.textFieldStyle(.roundedBorder)
TextBox(label: "Password", text: $handler.host.password, secure: true)
TextField("", text: $pubkeyStr, prompt: Text("Public Key"))
TextBox(label: "Publickey", text: $pubkeyStr)
.onChange(of: pubkeyStr) { _ in
let newStr = pubkeyStr.replacingOccurrences(of: "\r\n", with: "")
handler.host.publicKey = Data(newStr.utf8)
@@ -97,7 +88,7 @@ struct ConnectionView: View {
handler.host.publicKey = Data(newStr.utf8)
}
SecureField("", text: $privkeyStr, prompt: Text("Private Key"))
TextBox(label: "Privatekey", text: $privkeyStr, secure: true)
.onSubmit {
let newStr = privkeyStr.replacingOccurrences(of: "\r\n", with: "")
handler.host.privateKey = Data(newStr.utf8)
@@ -107,7 +98,7 @@ struct ConnectionView: View {
handler.host.privateKey = Data(newStr.utf8)
}
TextField("", text: $handler.host.passphrase, prompt: Text("Passphrase (Optional)"))
TextBox(label: "Passphrase", text: $handler.host.passphrase)
}
Button() {

View File

@@ -0,0 +1,31 @@
//
// TextBoxWLabel.swift
// ShhShell
//
// Created by neon443 on 30/06/2025.
//
import SwiftUI
struct TextBox: View {
@State var label: String
@Binding var text: String
@State var secure: Bool = false
@State var keyboardType: UIKeyboardType = .default
var body: some View {
HStack {
Text(label)
Spacer()
if secure {
SecureField("", text: $text)
} else {
TextField("", text: $text)
}
}
}
}
#Preview {
TextBox(label: "Label", text: .constant("asdflkajsdl"))
}

View File

@@ -47,15 +47,6 @@ struct ShellView: View {
.navigationTitle(handler.title)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem {
Button() {
handler.disconnect()
if !handler.connected { dismiss() }
} label: {
Label("Disconnect", systemImage: "xmark.app.fill")
}
}
//TODO: FIX
ToolbarItem(placement: .cancellationAction) {
Button() {
dismiss()
@@ -63,6 +54,14 @@ struct ShellView: View {
Label("Close", systemImage: "arrow.down.right.and.arrow.up.left")
}
}
ToolbarItem(placement: .cancellationAction) {
Button() {
handler.disconnect()
if !handler.connected { dismiss() }
} label: {
Label("Disconnect", systemImage: "xmark.app.fill")
}
}
}
}
}