FPUConfigRootView.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  41. .onAppear(perform: configureView)
  42. .navigationBarTitle("Fat and Protein")
  43. .navigationBarTitleDisplayMode(.automatic)
  44. }
  45. }
  46. }