SettingInputSection.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import SwiftUI
  2. struct SettingInputSection: View {
  3. enum InputType {
  4. case decimal
  5. case boolean
  6. }
  7. @Binding var decimalValue: Decimal
  8. @Binding var booleanValue: Bool
  9. @Binding var showHint: Bool
  10. @Binding var selectedVerboseHint: String?
  11. var type: InputType
  12. var label: String
  13. var shortHint: String
  14. var verboseHint: String
  15. var headerText: String?
  16. var footerText: String?
  17. var body: some View {
  18. Section(
  19. content: {
  20. VStack {
  21. if type == .decimal {
  22. HStack {
  23. Text(label)
  24. TextFieldWithToolBar(
  25. text: Binding(
  26. get: { decimalValue },
  27. set: { decimalValue = $0 }
  28. ),
  29. placeholder: decimalValue.description,
  30. numberFormatter: NumberFormatter()
  31. )
  32. }.padding(.top)
  33. } else if type == .boolean {
  34. HStack {
  35. Toggle(isOn: $booleanValue) {
  36. Text(label)
  37. }
  38. }
  39. }
  40. HStack(alignment: .top) {
  41. Text(shortHint)
  42. .font(.footnote)
  43. .foregroundColor(.secondary)
  44. .lineLimit(nil)
  45. Spacer()
  46. Button(
  47. action: {
  48. showHint.toggle()
  49. selectedVerboseHint = showHint ? verboseHint : nil
  50. },
  51. label: {
  52. HStack {
  53. Image(systemName: "questionmark.circle")
  54. }
  55. }
  56. )
  57. }.padding(type == .boolean ? .vertical : .bottom)
  58. }
  59. },
  60. header: {
  61. if let headerText = headerText {
  62. Text(headerText)
  63. }
  64. },
  65. footer: {
  66. if let footerText = footerText {
  67. Text(footerText)
  68. }
  69. }
  70. ).listRowBackground(Color.chart)
  71. }
  72. }