From d68e419d185e88f37f09cf237d110d49355c5f2d Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Wed, 6 Nov 2019 19:57:52 -0500 Subject: [PATCH] Fix button styling --- free-sidecar/ContentView.swift | 25 ++++++++++++++++++++++--- free-sidecar/Info.plist | 4 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/free-sidecar/ContentView.swift b/free-sidecar/ContentView.swift index 1a9edee..bad6335 100644 --- a/free-sidecar/ContentView.swift +++ b/free-sidecar/ContentView.swift @@ -8,6 +8,26 @@ import SwiftUI +struct ModelButtonStyle: ButtonStyle { + let isEnabled: Bool + + init(isEnabled: Bool) { + self.isEnabled = isEnabled + } + + func makeBody(configuration: Self.Configuration) -> some View { + let borderColor = self.isEnabled ? Color.green : Color.orange + let backgroundColor = configuration.isPressed ? Color.clear : borderColor + + return configuration.label + .foregroundColor(configuration.isPressed ? Color.white : Color.black) + .background(backgroundColor) + .border(borderColor, width: 2) + .cornerRadius(4) + .padding(2) + } +} + struct ContentView: View { @State var selectedURL: URL? @State var models: [Model] = [] @@ -66,7 +86,6 @@ struct ContentView: View { if result == .OK { self.selectedURL = panel.url self.models = dostuff2(sidecarCore: panel.url!); - } } }) { @@ -87,9 +106,9 @@ struct ContentView: View { self.models = dostuff2(sidecarCore: self.selectedURL!) }) { Text(model.enabled ? "\(model.str) enabled" : "Enable \(model.str)") - .foregroundColor(Color.black) + .padding() } - .background(model.enabled ? Color.green : Color.orange) + .buttonStyle(ModelButtonStyle(isEnabled: model.enabled)) }.frame(minHeight: 300) } else { Text("Select a SidecarCore first") diff --git a/free-sidecar/Info.plist b/free-sidecar/Info.plist index 60dface..23d324e 100644 --- a/free-sidecar/Info.plist +++ b/free-sidecar/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.1 + 1.2 CFBundleVersion - 2 + 3 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright