FPUConfigRootView.swift 2.7 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("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 Duration 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 into future carb equivalents, using the Warsaw method (total kcal/10).\n\nDelay is time from now until first future carb entry. Maximum duration is the maximum time in hours, in total, which the carb equivalents will allocate. Interval means the number of minutes betewen these entries. Override setting is for safety and tuning. The higher, the larger the total amount of carb equivalents. Compensating for an increased total carb amount with an increased IC ratio is recommended.\n\nDefault settings: Delay: 60 min, Time Cap: 8 h, Interval: 60 min, Factor: 0.5."
  48. )
  49. )
  50. {}
  51. }
  52. .onAppear(perform: configureView)
  53. .navigationBarTitle("Fat and Protein")
  54. .navigationBarTitleDisplayMode(.automatic)
  55. }
  56. }
  57. }