Skip to content

Commit f8d4915

Browse files
committed
Add progress bar
1 parent 71ec66b commit f8d4915

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

notch-prompter/PrompterView.swift

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
struct PrompterView: View {
44
@ObservedObject var viewModel: PrompterViewModel
55

6-
// Measure content height to loop or stop appropriately
6+
// Measure content height to stop appropriately
77
@State private var contentHeight: CGFloat = 0
88

99
// Tracks whether we paused due to hover and what the previous play state was
@@ -212,6 +212,18 @@ struct PrompterContentView: View {
212212
}
213213
}
214214

215+
// Progress bar on the right side
216+
if viewModel.showProgressBar {
217+
HStack {
218+
Spacer()
219+
ProgressBarView(
220+
currentOffset: viewModel.offset,
221+
totalHeight: contentHeight,
222+
theme: viewModel.prompterTheme
223+
)
224+
}
225+
}
226+
215227
// Hover controls overlay
216228
if showControls && viewModel.showHoverControls {
217229
VStack {
@@ -368,6 +380,7 @@ struct PrompterContentView: View {
368380
}
369381
}
370382

383+
// MARK: - Height reader
371384
private struct HeightReader: View {
372385
@Binding var height: CGFloat
373386
var body: some View {
@@ -380,3 +393,35 @@ private struct HeightReader: View {
380393
}
381394
}
382395
}
396+
397+
398+
// MARK: - Progress bar
399+
struct ProgressBarView: View {
400+
let currentOffset: CGFloat
401+
let totalHeight: CGFloat
402+
let theme: PrompterTheme
403+
404+
private var progress: Double {
405+
guard totalHeight > 0 else { return 0 }
406+
return min(max(Double(currentOffset / totalHeight), 0), 1.0)
407+
}
408+
409+
var body: some View {
410+
GeometryReader { geo in
411+
ZStack(alignment: .top) {
412+
RoundedRectangle(cornerRadius: 2)
413+
.fill(theme.textColor.opacity(0.15))
414+
.frame(width: 4)
415+
RoundedRectangle(cornerRadius: 2) // Progres
416+
.fill(theme.textColor.opacity(0.6))
417+
.frame(width: 4, height: geo.size.height * progress)
418+
}
419+
.frame(maxHeight: .infinity)
420+
}
421+
.frame(width: 4)
422+
.padding(.trailing, 8)
423+
.padding(.vertical, 8)
424+
.allowsHitTesting(false)
425+
}
426+
}
427+

notch-prompter/SettingsView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct SettingsView: View {
3232

3333
private var appVersion: String {
3434
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
35-
// let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "—" // I think this is too much for now
3635
return "\(version)"
3736
}
3837

@@ -727,7 +726,7 @@ struct LayoutTabView: View {
727726
get: { Double(viewModel.prompterHeight) },
728727
set: { viewModel.prompterHeight = CGFloat($0) }
729728
),
730-
range: 20...500,
729+
range: 80...500,
731730
step: 10,
732731
unit: "px"
733732
)

0 commit comments

Comments
 (0)