remora-kit

RemoraKit, shared dive computer engine (Buhlmann ZHL-16C + GF) and SwiftUI components for Open Remora and Open Merou
git clone https://git.schurger.org/remora-kit.git
Log | Files | Refs | README | LICENSE

AlarmStyle.swift (1526B)


      1 // SPDX-License-Identifier: GPL-2.0-only
      2 import SwiftUI
      3 
      4 /// Alarm (violation, depth unknown): the whole screen flashes red. Put it behind the dive screen.
      5 public struct AlarmFlash: View {
      6     public init() {}
      7 
      8     public var body: some View {
      9         TimelineView(.periodic(from: .now, by: 0.4)) { context in
     10             let on = Int(context.date.timeIntervalSinceReferenceDate / 0.4) % 2 == 0
     11             Color.red.opacity(on ? 0.85 : 0.15).ignoresSafeArea()
     12         }
     13     }
     14 }
     15 
     16 extension View {
     17     /// Warning: the value concerned blinks (nothing moves when `active` is false).
     18     @ViewBuilder public func blinking(_ active: Bool) -> some View {
     19         if active {
     20             TimelineView(.periodic(from: .now, by: 0.4)) { context in
     21                 let on = Int(context.date.timeIntervalSinceReferenceDate / 0.4) % 2 == 0
     22                 self.opacity(on ? 1 : 0.15)
     23             }
     24         } else {
     25             self
     26         }
     27     }
     28 }
     29 
     30 /// Shown over the dive screen while the depth is unknown underwater.
     31 public struct DepthUnknownBanner: View {
     32     var scale: CGFloat
     33 
     34     public init(scale: CGFloat = 1) { self.scale = scale }
     35 
     36     public var body: some View {
     37         Text("DEPTH UNKNOWN\nFollow your primary computer", bundle: .module)
     38             .font(.system(size: 13 * scale, weight: .heavy, design: .rounded))
     39             .multilineTextAlignment(.center)
     40             .padding(6 * scale)
     41             .frame(maxWidth: .infinity)
     42             .background(.red, in: RoundedRectangle(cornerRadius: 8 * scale))
     43     }
     44 }