FPUConfigRootView.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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("Delay In Minutes")
  26. Spacer()
  27. DecimalTextField("8", value: $state.delay, formatter: intFormater)
  28. }
  29. HStack {
  30. Text("Maximum Time Cap In Hours")
  31. Spacer()
  32. DecimalTextField("8", value: $state.timeCap, formatter: intFormater)
  33. }
  34. HStack {
  35. Text("Interval In Minutes")
  36. Spacer()
  37. DecimalTextField("60", value: $state.minuteInterval, formatter: intFormater)
  38. }
  39. HStack {
  40. Text("Override with a factor of ")
  41. Spacer()
  42. DecimalTextField("0.8", value: $state.individualAdjustmentFactor, formatter: conversionFormatter)
  43. }
  44. }
  45. Section(
  46. footer: Text(
  47. "Allows fat and protein to be converted to future carb equivalents.\n\nDefault settings:\n\nDelay: 60 minutes\nTime Cap: 8 hours\nInterval: 60 min\nFactor: 0.5"
  48. )
  49. )
  50. {}
  51. }
  52. .onAppear(perform: configureView)
  53. .navigationBarTitle("Fat and Protein")
  54. .navigationBarTitleDisplayMode(.automatic)
  55. }
  56. }
  57. }