To enhance the user interface of your macOS application, consider the following improvements:
-
Rounded Borders and Backgrounds: Apply rounded corners and background colors to your views to create a more polished appearance.
-
Consistent Padding and Spacing: Ensure uniform padding and spacing between elements for a balanced layout.
-
Semantic Colors: Utilize semantic colors like .primary and .secondary to ensure your app adapts well to different system themes, including light and dark modes[1].
-
Modular Components: Break down your UI into smaller, reusable components to improve maintainability and readability[2].
Here's an updated version of your ContentView incorporating these enhancements:
import SwiftUI
struct ContentView: View {
@StateObject private var monitor = USBMonitor()
var body: some View {
VStack(spacing: 20) {
HeaderView()
StatusMessageView(message: monitor.statusMessage)
if !monitor.deviceName.isEmpty {
DeviceInfoView(label: "Device:", value: monitor.deviceName)
}
if !monitor.serialNumber.isEmpty {
SerialNumberView(serialNumber: monitor.serialNumber)
}
ActionButtonsView(
fetchAction: monitor.fetchSerial,
isFetchDisabled: monitor.deviceName.isEmpty || !monitor.deviceIsReady,
quitAction: { NSApp.terminate(nil) }
)
}
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color(.windowBackgroundColor)))
.padding()
}
}
struct HeaderView: View {
var body: some View {
Text("🔌 USB Bridge Device Monitor")
.font(.title2)
.bold()
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.primary.opacity(0.1)))
}
}
struct StatusMessageView: View {
let message: String
var body: some View {
Text(message)
.multilineTextAlignment(.center)
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.secondary.opacity(0.1)))
}
}
struct DeviceInfoView: View {
let label: String
let value: String
var body: some View {
HStack {
Text(label)
.font(.headline)
Text(value)
}
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.secondary.opacity(0.1)))
}
}
struct SerialNumberView: View {
let serialNumber: String
var body: some View {
HStack {
Text("Serial Number:")
Text(serialNumber)
Button("Copy") {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(serialNumber, forType: .string)
}
.buttonStyle(BorderlessButtonStyle())
}
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.secondary.opacity(0.1)))
}
}
struct ActionButtonsView: View {
let fetchAction: () -> Void
let isFetchDisabled: Bool
let quitAction: () -> Void
var body: some View {
HStack(spacing: 20) {
Button("Fetch Serial", action: fetchAction)
.disabled(isFetchDisabled)
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.accentColor))
.foregroundColor(.white)
Button("Quit", action: quitAction)
.padding()
.background(RoundedRectangle(cornerRadius: 10).fill(Color.red))
.foregroundColor(.white)
}
}
}
#Preview {
ContentView()
}