FPUConfigRootView.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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("Conversion settings")) {
  21. HStack {
  22. Text("Delay In Minutes")
  23. Spacer()
  24. DecimalTextField("60", value: $state.delay, formatter: intFormater)
  25. }
  26. HStack {
  27. Text("Maximum Duration In Hours")
  28. Spacer()
  29. DecimalTextField("8", value: $state.timeCap, formatter: intFormater)
  30. }
  31. HStack {
  32. Text("Interval In Minutes")
  33. Spacer()
  34. DecimalTextField("30", value: $state.minuteInterval, formatter: intFormater)
  35. }
  36. HStack {
  37. Text("Override With A Factor Of ")
  38. Spacer()
  39. DecimalTextField("0.5", value: $state.individualAdjustmentFactor, formatter: conversionFormatter)
  40. }
  41. }
  42. Section(
  43. footer: Text(
  44. "Allows fat and protein to be converted into future carb equivalents using the Warsaw formula of kilocalories divided by 10.\n\nThis spreads the carb equivilants over a maximum duration setting that can be configured from 5-12 hours.\n\nDelay is time from now until the first future carb entry.\n\nInterval in minutes is how many minutes are between entries. The shorter the interval, the smoother the result. 10, 15, 20, 30, or 60 are reasonable choices.\n\nAdjustment factor is how much effect the fat and protein has on the entries. 1.0 is full effect (original Warsaw Method) and 0.5 is half effect. Note that you may find that your normal carb ratio needs to increase to a larger number if you begin adding fat and protein entries. For this reason, it is best to start with a factor of about 0.5 to ease into it.\n\nDefault settings: Time Cap: 8 h, Interval: 30 min, Factor: 0.5, Delay 60 min"
  45. )
  46. )
  47. {}
  48. }
  49. .onAppear(perform: configureView)
  50. .navigationBarTitle("Fat and Protein")
  51. .navigationBarTitleDisplayMode(.automatic)
  52. }
  53. }
  54. }