Skip to content

Commit f018832

Browse files
authored
changed spacing and font-sizes & added drawer open animation (#138)
1 parent 91ac181 commit f018832

File tree

1 file changed

+56
-38
lines changed

1 file changed

+56
-38
lines changed

CodeEditModules/Modules/StatusBar/src/StatusBar.swift

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ public struct StatusBarView: View {
1212

1313
@ObservedObject private var model: StatusBarModel
1414

15+
private var toolbarFont: Font = .system(size: 11)
16+
1517
public init() {
1618
self.model = .init()
1719
}
1820

19-
public var body: some View {
21+
public var body: some View {
2022
VStack(spacing: 0) {
2123
bar
22-
if model.isExpanded {
24+
// if model.isExpanded {
2325
terminal
24-
}
26+
// }
2527
}
26-
// removes weird light gray bar above when in light mode
28+
// removes weird light gray bar above when in light mode
2729
.padding(.top, -8) // (comment out to make it look normal in preview)
28-
}
30+
}
2931

3032
private var dragGesture: some Gesture {
3133
DragGesture()
@@ -42,8 +44,8 @@ public struct StatusBarView: View {
4244
ZStack {
4345
Rectangle()
4446
.foregroundStyle(.bar)
45-
HStack(spacing: 14) {
46-
HStack(spacing: 8) {
47+
HStack(spacing: 15) {
48+
HStack(spacing: 5) {
4749
labelButton(model.errorCount.formatted(), image: "xmark.octagon")
4850
labelButton(model.warningCount.formatted(), image: "exclamationmark.triangle")
4951
}
@@ -77,17 +79,18 @@ public struct StatusBarView: View {
7779
private var terminal: some View {
7880
Rectangle()
7981
.foregroundColor(Color(red: 0.163, green: 0.163, blue: 0.188, opacity: 1.000))
80-
.frame(minHeight: 0, idealHeight: height, maxHeight: height)
82+
.frame(minHeight: 0, idealHeight: model.isExpanded ? height : 0, maxHeight: model.isExpanded ? height : 0)
8183
}
8284

8385
private func labelButton(_ text: String, image: String) -> some View {
8486
Button {
8587
// show errors/warnings
8688
} label: {
87-
HStack(spacing: 4) {
89+
HStack(spacing: 2) {
8890
Image(systemName: image)
89-
.font(.headline)
91+
.font(.callout.bold())
9092
Text(text)
93+
.font(toolbarFont)
9194
}
9295
}
9396
.buttonStyle(.borderless)
@@ -102,13 +105,16 @@ public struct StatusBarView: View {
102105
}
103106

104107
private var branchPicker: some View {
105-
Menu(model.branches[model.selectedBranch]) {
108+
Menu {
106109
ForEach(model.branches.indices, id: \.self) { branch in
107110
Button { model.selectedBranch = branch } label: {
108111
Text(model.branches[branch])
109112
// checkout branch
110113
}
111114
}
115+
} label: {
116+
Text(model.branches[model.selectedBranch])
117+
.font(toolbarFont)
112118
}
113119
.menuStyle(.borderlessButton)
114120
.fixedSize()
@@ -132,14 +138,14 @@ public struct StatusBarView: View {
132138
}
133139
} label: {
134140
Image(systemName: "arrow.triangle.2.circlepath")
135-
.imageScale(.large)
141+
.imageScale(.medium)
136142
.rotationEffect(.degrees(model.isReloading ? 360 : 0))
137143
.animation(animation, value: model.isReloading)
138144
.opacity(model.isReloading ? 1 : 0)
139145
// A bit of a hacky solution to prevent spinning counterclockwise once `reloading` changes to `false`
140146
.overlay {
141147
Image(systemName: "arrow.triangle.2.circlepath")
142-
.imageScale(.large)
148+
.imageScale(.medium)
143149
.opacity(model.isReloading ? 0 : 1)
144150
}
145151

@@ -163,6 +169,7 @@ public struct StatusBarView: View {
163169

164170
private var cursorLocationLabel: some View {
165171
Text("Ln \(model.currentLine), Col \(model.currentCol)")
172+
.font(toolbarFont)
166173
.foregroundStyle(.primary)
167174
.onHover { hovering in
168175
if hovering {
@@ -174,8 +181,11 @@ public struct StatusBarView: View {
174181
}
175182

176183
private var indentSelector: some View {
177-
Menu("2 Spaces") {
184+
Menu {
178185
// 2 spaces, 4 spaces, ...
186+
} label: {
187+
Text("2 Spaces")
188+
.font(toolbarFont)
179189
}
180190
.menuStyle(.borderlessButton)
181191
.fixedSize()
@@ -189,45 +199,53 @@ public struct StatusBarView: View {
189199
}
190200

191201
private var encodingSelector: some View {
192-
Menu("UTF 8") {
202+
Menu {
193203
// UTF 8, ASCII, ...
204+
} label: {
205+
Text("UTF 8")
206+
.font(toolbarFont)
194207
}
195-
.menuStyle(.borderlessButton)
196-
.fixedSize()
197-
.onHover { hovering in
198-
if hovering {
199-
NSCursor.pointingHand.push()
200-
} else {
201-
NSCursor.pop()
202-
}
208+
.menuStyle(.borderlessButton)
209+
.fixedSize()
210+
.onHover { hovering in
211+
if hovering {
212+
NSCursor.pointingHand.push()
213+
} else {
214+
NSCursor.pop()
203215
}
216+
}
204217
}
205218

206219
private var lineEndSelector: some View {
207-
Menu("LF") {
220+
Menu {
208221
// LF, CRLF
222+
} label: {
223+
Text("LF")
224+
.font(toolbarFont)
209225
}
210-
.menuStyle(.borderlessButton)
211-
.fixedSize()
212-
.onHover { hovering in
213-
if hovering {
214-
NSCursor.pointingHand.push()
215-
} else {
216-
NSCursor.pop()
217-
}
226+
.menuStyle(.borderlessButton)
227+
.fixedSize()
228+
.onHover { hovering in
229+
if hovering {
230+
NSCursor.pointingHand.push()
231+
} else {
232+
NSCursor.pop()
218233
}
234+
}
219235
}
220236

221237
private var expandButton: some View {
222238
Button {
223-
model.isExpanded.toggle()
224-
if model.isExpanded && height < 1 {
225-
height = 300
239+
withAnimation {
240+
model.isExpanded.toggle()
241+
if model.isExpanded && height < 1 {
242+
height = 300
243+
}
226244
}
227245
// Show/hide terminal window
228246
} label: {
229247
Image(systemName: "rectangle.bottomthird.inset.filled")
230-
.imageScale(.large)
248+
.imageScale(.medium)
231249
}
232250
.tint(model.isExpanded ? .accentColor : .primary)
233251
.buttonStyle(.borderless)
@@ -243,12 +261,12 @@ public struct StatusBarView: View {
243261

244262
@available(macOS 12, *)
245263
struct SwiftUIView_Previews: PreviewProvider {
246-
static var previews: some View {
264+
static var previews: some View {
247265
ZStack(alignment: .bottom) {
248266
Color.white
249267
StatusBarView()
250268
.previewLayout(.fixed(width: 1.336, height: 500.0))
251269
.preferredColorScheme(.light)
252270
}
253-
}
271+
}
254272
}

0 commit comments

Comments
 (0)