Skip to content

Commit d4dcc89

Browse files
committed
Improve button styles
1 parent 56fac87 commit d4dcc89

File tree

9 files changed

+128
-24
lines changed

9 files changed

+128
-24
lines changed

DeltaClient.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
78427864268FBA2200FF16C2 /* AssetError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78427862268FBA2200FF16C2 /* AssetError.swift */; };
7272
7842786F268FBCEF00FF16C2 /* VersionManifest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7842786E268FBCEF00FF16C2 /* VersionManifest.swift */; };
7373
78427870268FBCEF00FF16C2 /* VersionManifest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7842786E268FBCEF00FF16C2 /* VersionManifest.swift */; };
74+
7845DDC5269A4DDE008FC70E /* PrimaryButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDC4269A4DDE008FC70E /* PrimaryButtonStyle.swift */; };
75+
7845DDC6269A4DDE008FC70E /* PrimaryButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDC4269A4DDE008FC70E /* PrimaryButtonStyle.swift */; };
76+
7845DDCA269A4E00008FC70E /* SecondaryButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDC9269A4E00008FC70E /* SecondaryButtonStyle.swift */; };
77+
7845DDCB269A4E00008FC70E /* SecondaryButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDC9269A4E00008FC70E /* SecondaryButtonStyle.swift */; };
78+
7845DDCF269A5350008FC70E /* DisabledButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDCE269A5350008FC70E /* DisabledButtonStyle.swift */; };
79+
7845DDD0269A5350008FC70E /* DisabledButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7845DDCE269A5350008FC70E /* DisabledButtonStyle.swift */; };
7480
788195C12691E2960099575B /* LoadingState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788195C02691E2960099575B /* LoadingState.swift */; };
7581
788195C22691E2960099575B /* LoadingState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788195C02691E2960099575B /* LoadingState.swift */; };
7682
788538892695C8BB00932F71 /* EditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788538882695C8BB00932F71 /* EditorView.swift */; };
@@ -151,6 +157,9 @@
151157
7842785D268FB91F00FF16C2 /* VersionsManifest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionsManifest.swift; sourceTree = "<group>"; };
152158
78427862268FBA2200FF16C2 /* AssetError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetError.swift; sourceTree = "<group>"; };
153159
7842786E268FBCEF00FF16C2 /* VersionManifest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionManifest.swift; sourceTree = "<group>"; };
160+
7845DDC4269A4DDE008FC70E /* PrimaryButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryButtonStyle.swift; sourceTree = "<group>"; };
161+
7845DDC9269A4E00008FC70E /* SecondaryButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryButtonStyle.swift; sourceTree = "<group>"; };
162+
7845DDCE269A5350008FC70E /* DisabledButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledButtonStyle.swift; sourceTree = "<group>"; };
154163
788195C02691E2960099575B /* LoadingState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingState.swift; sourceTree = "<group>"; };
155164
788538882695C8BB00932F71 /* EditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorView.swift; sourceTree = "<group>"; };
156165
78AA801F2699329300664150 /* VideoConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoConfig.swift; sourceTree = "<group>"; };
@@ -356,6 +365,9 @@
356365
78050DE6269514ED0024C049 /* Config */,
357366
78E18844267DB6050069E701 /* RouterView.swift */,
358367
78050DEC269588510024C049 /* IconButton.swift */,
368+
7845DDC4269A4DDE008FC70E /* PrimaryButtonStyle.swift */,
369+
7845DDC9269A4E00008FC70E /* SecondaryButtonStyle.swift */,
370+
7845DDCE269A5350008FC70E /* DisabledButtonStyle.swift */,
359371
);
360372
path = Views;
361373
sourceTree = "<group>";
@@ -562,13 +574,16 @@
562574
78427845268F275A00FF16C2 /* ConfigManager.swift in Sources */,
563575
7842785E268FB91F00FF16C2 /* VersionsManifest.swift in Sources */,
564576
78B6B1C42687E3440041B1E1 /* StorageError.swift in Sources */,
577+
7845DDCA269A4E00008FC70E /* SecondaryButtonStyle.swift in Sources */,
565578
7806A8A226968B1C002F4115 /* EmailField.swift in Sources */,
579+
7845DDC5269A4DDE008FC70E /* PrimaryButtonStyle.swift in Sources */,
566580
78B6B1A52687D9470041B1E1 /* ErrorView.swift in Sources */,
567581
78ABBBC926964A0F00475BFE /* OptionalNumberField.swift in Sources */,
568582
78C1C01C2696644500604D15 /* ServerEditorView.swift in Sources */,
569583
78E18845267DB6050069E701 /* RouterView.swift in Sources */,
570584
78203EB02696B27100D97A93 /* ConfigError.swift in Sources */,
571585
78427863268FBA2200FF16C2 /* AssetError.swift in Sources */,
586+
7845DDCF269A5350008FC70E /* DisabledButtonStyle.swift in Sources */,
572587
78B4B70D2696706B00DF28B2 /* SettingsView.swift in Sources */,
573588
7839921326911DCD005E93FD /* MetalView.swift in Sources */,
574589
7837265926991DAF00E39326 /* ClientInputDelegate.swift in Sources */,
@@ -617,13 +632,16 @@
617632
78427846268F275A00FF16C2 /* ConfigManager.swift in Sources */,
618633
7842785F268FB91F00FF16C2 /* VersionsManifest.swift in Sources */,
619634
78B6B1C52687E3440041B1E1 /* StorageError.swift in Sources */,
635+
7845DDCB269A4E00008FC70E /* SecondaryButtonStyle.swift in Sources */,
620636
7806A8A326968B1C002F4115 /* EmailField.swift in Sources */,
637+
7845DDC6269A4DDE008FC70E /* PrimaryButtonStyle.swift in Sources */,
621638
78B6B1A62687D9470041B1E1 /* ErrorView.swift in Sources */,
622639
78ABBBCA26964A0F00475BFE /* OptionalNumberField.swift in Sources */,
623640
78C1C01D2696644500604D15 /* ServerEditorView.swift in Sources */,
624641
78E18846267DB6050069E701 /* RouterView.swift in Sources */,
625642
78203EB12696B27100D97A93 /* ConfigError.swift in Sources */,
626643
78427864268FBA2200FF16C2 /* AssetError.swift in Sources */,
644+
7845DDD0269A5350008FC70E /* DisabledButtonStyle.swift in Sources */,
627645
78B4B710269670B400DF28B2 /* SettingsView.swift in Sources */,
628646
7839921426911DCD005E93FD /* MetalView.swift in Sources */,
629647
7837265A26991DAF00E39326 /* ClientInputDelegate.swift in Sources */,

Shared/Views/Config/Account/AccountLoginView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct AccountLoginView: EditorView {
7575
TextField("Username", text: $username)
7676
}
7777
}
78-
.padding(.bottom, 8)
7978

8079
if let error = errorMessage {
8180
Text(error)
@@ -85,10 +84,12 @@ struct AccountLoginView: EditorView {
8584
HStack {
8685
if let cancel = cancelationHandler {
8786
Button("Cancel", action: cancel)
88-
.buttonStyle(BorderlessButtonStyle())
87+
.buttonStyle(SecondaryButtonStyle())
8988
}
9089
Button("Login", action: login)
90+
.buttonStyle(PrimaryButtonStyle())
9191
}
92+
.padding(.top, 8)
9293
} else {
9394
Text("Logging in..")
9495
}

Shared/Views/Config/EditableList/EditableList.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,26 @@ struct EditableList<Row: View, ItemEditor: EditorView>: View {
114114
}
115115
}
116116

117-
Button("Add") {
118-
state.update(to: .addItem)
119-
}
120-
121-
if save != nil || cancel != nil {
122-
HStack {
123-
if let cancel = cancel {
124-
Button("Cancel", action: cancel)
125-
.buttonStyle(BorderlessButtonStyle())
126-
}
127-
if let save = save {
128-
Button("Done", action: save)
117+
VStack {
118+
Button("Add") {
119+
state.update(to: .addItem)
120+
}
121+
.buttonStyle(SecondaryButtonStyle())
122+
123+
if save != nil || cancel != nil {
124+
HStack {
125+
if let cancel = cancel {
126+
Button("Cancel", action: cancel)
127+
.buttonStyle(SecondaryButtonStyle())
128+
}
129+
if let save = save {
130+
Button("Save", action: save)
131+
.buttonStyle(PrimaryButtonStyle())
132+
}
129133
}
130134
}
131135
}
136+
.frame(width: 200)
132137
}
133138
case .addItem:
134139
itemEditor.init(nil, completion: { newItem in

Shared/Views/Config/Server/ServerEditorView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ struct ServerEditorView: EditorView {
1616
var cancelationHandler: (() -> Void)?
1717

1818
@State var isIpValid = false
19+
/// True if this is editing an existing server.
20+
let isEditor: Bool
1921

2022
init(_ item: ServerDescriptor?, completion: @escaping (ServerDescriptor) -> Void, cancelation: (() -> Void)?) {
2123
completionHandler = completion
2224
cancelationHandler = cancelation
2325

26+
isEditor = item == nil
2427
_descriptor = State(initialValue: item ?? ServerDescriptor(name: "", host: "", port: nil))
2528
}
2629

@@ -46,12 +49,14 @@ struct ServerEditorView: EditorView {
4649
HStack {
4750
if let cancel = cancelationHandler {
4851
Button("Cancel", action: cancel)
49-
.buttonStyle(BorderlessButtonStyle())
52+
.buttonStyle(SecondaryButtonStyle())
5053
}
51-
Button("Save") {
54+
Button(isEditor ? "Save" : "Add") {
5255
if verify() { completionHandler(descriptor) }
5356
}
57+
.buttonStyle(PrimaryButtonStyle())
5458
}
59+
.padding(.top, 8)
5560
}
5661
.frame(width: 200)
5762
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// DisabledButtonStyle.swift
3+
// DeltaClient
4+
//
5+
// Created by Rohan van Klinken on 11/7/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct DisabledButtonStyle: ButtonStyle {
11+
func makeBody(configuration: Configuration) -> some View {
12+
HStack {
13+
Spacer()
14+
configuration.label.foregroundColor(.gray)
15+
Spacer()
16+
}
17+
.padding(6)
18+
.background(Color.secondary.brightness(-0.4).cornerRadius(4))
19+
}
20+
}

Shared/Views/Play/PlayServerView.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ struct PlayServerView: View {
9090
VStack {
9191
Text("Downloading terrain..")
9292
Button("Cancel", action: disconnect)
93+
.buttonStyle(SecondaryButtonStyle())
94+
.frame(width: 150)
9395
}
9496
case .playing:
9597
ZStack {
@@ -111,15 +113,20 @@ struct PlayServerView: View {
111113
if !cursorCaptured {
112114
switch overlayState.current {
113115
case .menu:
116+
// Invisible button for escape to exit menu. Because keyboard shortcuts aren't working with my custom button styles
117+
Button("Back to game", action: inputDelegate.captureCursor)
118+
.keyboardShortcut(.escape, modifiers: [])
119+
.opacity(0)
120+
114121
VStack {
115122
Button("Back to game", action: inputDelegate.captureCursor)
116-
.keyboardShortcut(.escape, modifiers: [])
117-
.frame(width: 100)
123+
.buttonStyle(PrimaryButtonStyle())
118124
Button("Settings", action: { overlayState.update(to: .settings) })
119-
.frame(width: 100)
125+
.buttonStyle(SecondaryButtonStyle())
120126
Button("Disconnect", action: disconnect)
121-
.frame(width: 100)
127+
.buttonStyle(SecondaryButtonStyle())
122128
}
129+
.frame(width: 200)
123130
case .settings:
124131
InGameSettingsView(eventBus: client.eventBus, onDone: {
125132
overlayState.update(to: .menu)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// PrimaryButtonStyle.swift
3+
// DeltaClient
4+
//
5+
// Created by Rohan van Klinken on 11/7/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct PrimaryButtonStyle: ButtonStyle {
11+
func makeBody(configuration: Configuration) -> some View {
12+
HStack {
13+
Spacer()
14+
configuration.label.foregroundColor(.white)
15+
Spacer()
16+
}
17+
.padding(6)
18+
.background(Color.accentColor.brightness(configuration.isPressed ? 0.15 : 0).cornerRadius(4))
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// SecondaryButtonStyle.swift
3+
// DeltaClient
4+
//
5+
// Created by Rohan van Klinken on 11/7/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct SecondaryButtonStyle: ButtonStyle {
11+
func makeBody(configuration: Configuration) -> some View {
12+
HStack {
13+
Spacer()
14+
configuration.label.foregroundColor(.white)
15+
Spacer()
16+
}
17+
.padding(6)
18+
.background(Color.secondary.brightness(configuration.isPressed ? 0 : -0.15).cornerRadius(4))
19+
}
20+
}

Shared/Views/ServerList/ServerDetail.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ struct ServerDetail: View {
2626
Text(verbatim: "\(info.numPlayers)/\(info.maxPlayers) online")
2727
Text("version: \(info.versionName) \(info.protocolVersion == Constants.protocolVersion ? "" : "(incompatible)")")
2828
.padding(.bottom, 8)
29+
Button("Play") {
30+
appState.update(to: .playServer(descriptor))
31+
}
32+
.buttonStyle(SecondaryButtonStyle())
33+
.frame(width: 150)
2934
case let .failure(error):
3035
Text("Connection failed: \(error.localizedDescription)")
3136
.padding(.bottom, 8)
37+
Button("Play") { }
38+
.buttonStyle(SecondaryButtonStyle())
39+
.frame(width: 150)
40+
.disabled(false)
3241
}
3342
} else {
3443
Text("Pinging..")
3544
.padding(.bottom, 8)
36-
}
37-
38-
Button("Play") {
39-
appState.update(to: .playServer(descriptor))
45+
Button("Play") { }
46+
.buttonStyle(DisabledButtonStyle())
47+
.frame(width: 150)
4048
}
4149
}
4250
}

0 commit comments

Comments
 (0)