Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
fix(watch): the weigh-in's crown turns whole units, the tenth has its own tile
Duarte Santos86f36e1c7589
diff --git a/frontend/ios/App/Watch/OpenGymWatchApp.swift b/frontend/ios/App/Watch/OpenGymWatchApp.swiftindex c660bf21c..218cb1fa2 100644--- a/frontend/ios/App/Watch/OpenGymWatchApp.swift+++ b/frontend/ios/App/Watch/OpenGymWatchApp.swift@@ -779,34 +779,46 @@ struct ValueEditor: View {}/// The weigh-in before a workout started here, as the phone asks for it: the body weight on the-/// crown (in tenths), Save and start, or start without.+/// crown in two parts (whole units, then a tap on the tenth for the tenth), Save and start, or+/// start without. One crown in tenths ran a whole kilo away in a flick.struct WeighInView: View {@EnvironmentObject var store: SessionStore- @FocusState private var focused: Bool+ enum Part: Hashable { case whole, tenth }+ @FocusState private var part: Part?@ScaledMetric(relativeTo: .largeTitle) private var size: CGFloat = 40+ private var whole: Binding<Double> {+ Binding(get: { WeighIn.parts(store.bodyWeight).whole },+ set: { store.bodyWeight = WeighIn.join(whole: $0, tenth: WeighIn.parts(store.bodyWeight).tenth) })+ }+ private var tenth: Binding<Double> {+ Binding(get: { WeighIn.parts(store.bodyWeight).tenth },+ set: { store.bodyWeight = WeighIn.join(whole: WeighIn.parts(store.bodyWeight).whole, tenth: $0) })+ }+var body: some View {+ let p = WeighIn.parts(store.bodyWeight)ScrollView {VStack(spacing: 6) {Text("Quick check-in").font(.system(.headline, design: .rounded))- HStack(alignment: .firstTextBaseline, spacing: 2) {- Text(verbatim: String(format: "%.1f", store.bodyWeight))- .font(.system(size: size, weight: .semibold, design: .rounded).monospacedDigit())- .foregroundStyle(Theme.accent)- .contentTransition(.numericText())- Text(verbatim: store.unit).font(.system(size: 13, weight: .medium, design: .rounded)).foregroundStyle(.secondary)+ HStack(alignment: .firstTextBaseline, spacing: 0) {+ digits(String(Int(p.whole)), .whole, whole, 20...(store.unit == "lb" ? 700 : 320))+ Text(verbatim: ".").font(.system(size: size, weight: .semibold, design: .rounded)).foregroundStyle(.secondary)+ digits(String(Int(p.tenth)), .tenth, tenth, 0...9)+ Text(verbatim: " " + store.unit).font(.system(size: 13, weight: .medium, design: .rounded)).foregroundStyle(.secondary)}.lineLimit(1).minimumScaleFactor(0.5).frame(maxWidth: .infinity, minHeight: Theme.tap)- .focusable()- .focused($focused)- .digitalCrownRotation($store.bodyWeight, from: 20, through: store.unit == "lb" ? 700 : 320, by: 0.1,- sensitivity: .low, isContinuous: false, isHapticFeedbackEnabled: true).accessibilityElement(children: .ignore).accessibilityLabel(Text("Body weight")).accessibilityValue(Text(verbatim: String(format: "%.1f %@", store.bodyWeight, store.unit))).accessibilityHint(Text("Turn the Digital Crown to change it."))+ .accessibilityAdjustableAction { d in+ let v = store.bodyWeight + (d == .increment ? 0.1 : -0.1)+ let q = WeighIn.parts(v)+ store.bodyWeight = WeighIn.join(whole: q.whole, tenth: q.tenth)+ }Button { store.finishWeighIn(save: true) } label: {Text("Save & start workout").font(.body.weight(.semibold)).frame(maxWidth: .infinity, minHeight: Theme.tap)}@@ -824,7 +836,26 @@ struct WeighInView: View {}.padding(.horizontal, 4)}- .onAppear { focused = true }+ .onAppear { part = .whole }+ }++ /// One part of the number: the one the crown turns is in the accent colour on a soft tile,+ /// a tap on the other one hands the crown to it.+ private func digits(_ text: String, _ which: Part, _ value: Binding<Double>, _ range: ClosedRange<Double>) -> some View {+ let on = part == which+ return Text(verbatim: text)+ .font(.system(size: which == .whole ? size : size * 0.8, weight: .semibold, design: .rounded).monospacedDigit())+ .foregroundStyle(on ? Theme.accent : Color.white)+ .contentTransition(.numericText())+ .padding(.horizontal, 4)+ .frame(minWidth: Theme.tap * 0.7, minHeight: Theme.tap)+ .background(RoundedRectangle(cornerRadius: 10, style: .continuous).fill(on ? Theme.dim : Color.clear))+ .contentShape(Rectangle())+ .focusable()+ .focused($part, equals: which)+ .digitalCrownRotation(value, from: range.lowerBound, through: range.upperBound, by: 1,+ sensitivity: .low, isContinuous: false, isHapticFeedbackEnabled: true)+ .onTapGesture { part = which }}}diff --git a/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift b/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swiftindex 7fab1dc9a..848f1cc18 100644--- a/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift+++ b/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift@@ -490,3 +490,21 @@ enum Effort {return tops.firstIndex { rir <= $0 } ?? tops.count}}++/*+ * The weigh-in's crown, in two parts: the whole kilos (or pounds) and the tenth after the point.+ * One crown in tenths moved a whole kilo in a flick and was fiddly to stop on the right one.+ */+enum WeighIn {+ /// 79.4 → (79, 4). Rounded to the tenth first, so 79.95 is (80, 0), never (79, 10).+ static func parts(_ v: Double) -> (whole: Double, tenth: Double) {+ let tenths = (max(0, v) * 10).rounded()+ return ((tenths / 10).rounded(.down), tenths.truncatingRemainder(dividingBy: 10))+ }++ /// (79, 4) → 79.4, on the tenth's grid (no 79.40000001 to send to the phone).+ static func join(whole: Double, tenth: Double) -> Double {+ let t = min(9, max(0, tenth.rounded()))+ return (whole.rounded() * 10 + t) / 10+ }+}diff --git a/frontend/ios/App/WatchCore/Tests/WatchCoreTests/WeighInTests.swift b/frontend/ios/App/WatchCore/Tests/WatchCoreTests/WeighInTests.swiftnew file mode 100644index 000000000..b11b0d766--- /dev/null+++ b/frontend/ios/App/WatchCore/Tests/WatchCoreTests/WeighInTests.swift@@ -0,0 +1,23 @@+import XCTest+@testable import WatchCore++/// The weigh-in's crown in two parts: whole units, and the tenth on a tile of its own.+final class WeighInTests: XCTestCase {+ func testSplitsIntoWholeAndTenth() {+ XCTAssertEqual(WeighIn.parts(79.4).whole, 79)+ XCTAssertEqual(WeighIn.parts(79.4).tenth, 4)+ XCTAssertEqual(WeighIn.parts(80).tenth, 0)+ XCTAssertEqual(WeighIn.parts(79.95).whole, 80, "rounded to the tenth first")+ XCTAssertEqual(WeighIn.parts(79.95).tenth, 0)+ XCTAssertEqual(WeighIn.parts(0.3).whole, 0)+ }++ func testJoinsBackOnTheTenthsGrid() {+ XCTAssertEqual(WeighIn.join(whole: 79, tenth: 4), 79.4)+ XCTAssertEqual(WeighIn.join(whole: 80, tenth: 0), 80)+ XCTAssertEqual(WeighIn.join(whole: 79, tenth: 12), 79.9, "the tenth never carries over")+ let v = 72.3+ let p = WeighIn.parts(v)+ XCTAssertEqual(WeighIn.join(whole: p.whole, tenth: p.tenth), v)+ }+}