implement multi stopwatch
This commit is contained in:
56
MultiChrono/StopwatchRow.swift
Normal file
56
MultiChrono/StopwatchRow.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// StopwatchRow.swift
|
||||
// MultiChrono
|
||||
//
|
||||
// Created by Beatrice Dellacà on 26/01/26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct StopwatchRow: View {
|
||||
@ObservedObject var stopwatch: Stopwatch
|
||||
var onDelete: () -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Text(stopwatch.name)
|
||||
.font(.headline)
|
||||
Text("\(stopwatch.formattedTime)")
|
||||
.font(.largeTitle)
|
||||
.monospacedDigit()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
if stopwatch.isRunning {
|
||||
stopwatch.pause()
|
||||
} else {
|
||||
stopwatch.start()
|
||||
}
|
||||
}) {
|
||||
Image(systemName: stopwatch.isRunning ? "pause.circle.fill" : "play.circle.fill")
|
||||
.resizable()
|
||||
.frame(width: 44, height: 44)
|
||||
.foregroundStyle(stopwatch.isRunning ? .orange : .green)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
|
||||
Button(action: onDelete) {
|
||||
Image(systemName: "trash")
|
||||
.resizable()
|
||||
.frame(width: 24, height: 24)
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.padding(.leading, 10)
|
||||
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
StopwatchRow(stopwatch: Stopwatch(name: "Test Timer"), onDelete: {})
|
||||
}
|
||||
Reference in New Issue
Block a user