FPUConfigRootView.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import SwiftUI
  2. import Swinject
  3. extension FPUConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. private var conversionFormatter: NumberFormatter {
  8. let formatter = NumberFormatter()
  9. formatter.numberStyle = .decimal
  10. formatter.maximumFractionDigits = 1
  11. return formatter
  12. }
  13. private var intFormater: NumberFormatter {
  14. let formatter = NumberFormatter()
  15. formatter.allowsFloats = false
  16. return formatter
  17. }
  18. var body: some View {
  19. Form {
  20. Section(header: Text("Convert Fat and Protein")) {
  21. Toggle("Enable", isOn: $state.useFPUconversion)
  22. }
  23. Section(header: Text("Optional conversion settings")) {
  24. HStack {
  25. Text("Maximum Time Cap In Hours")
  26. Spacer()
  27. DecimalTextField("8", value: $state.timeCap, formatter: intFormater)
  28. }
  29. HStack {
  30. Text("Interval In Minutes")
  31. Spacer()
  32. DecimalTextField("60", value: $state.minuteInterval, formatter: intFormater)
  33. }
  34. HStack {
  35. Text("Override with a factor of ")
  36. Spacer()
  37. DecimalTextField("0.8", value: $state.individualAdjustmentFactor, formatter: conversionFormatter)
  38. }
  39. }
  40. Section(
  41. footer: Text(
  42. "Allows fat and protein to be converted to future carb equivalents.\n\nDefault settings:\n\nTime Cap: 8 hours\nInterval: 60 min\nFactor: 0.5"
  43. )
  44. )
  45. {}
  46. }
  47. .onAppear(perform: configureView)
  48. .navigationBarTitle("Fat and Protein")
  49. .navigationBarTitleDisplayMode(.automatic)
  50. }
  51. }
  52. }