BudgetCells.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // BudgetCells.swift
  3. // ydnab
  4. //
  5. // Created by Andrea Franceschini on 03/10/2020.
  6. //
  7. import SwiftUI
  8. /// Budget category, allows to view and edit a budget category.
  9. struct BudgetCategoryCell: View {
  10. /// The budget category being represented
  11. @State var category: BudgetCategory
  12. /// A formatted string of the amount budgeted for the category
  13. @State var amountText: String
  14. /// A positive/negative color to apply to the `amountText`
  15. @State var color: Color
  16. var body: some View {
  17. HStack {
  18. Text(category.name)
  19. Spacer()
  20. Text(amountText)
  21. .bold()
  22. .foregroundColor(color)
  23. }
  24. }
  25. }
  26. /// Budget section, aggregates the budgeted amounts for this section.
  27. struct BudgetSectionCell: View {
  28. /// The budget section being represented
  29. @State var section: BudgetSection
  30. /// A formatted string of the aggregated amount budgeted in this section
  31. @State var amountText: String
  32. /// A positive/negative color to apply to the `amountText`
  33. @State var color: Color
  34. @Environment(\.editMode) var editMode
  35. var body: some View {
  36. HStack {
  37. Text(section.name)
  38. .textCase(.none)
  39. Spacer()
  40. if editMode?.wrappedValue == .inactive {
  41. Text(amountText)
  42. .foregroundColor(color)
  43. }
  44. }
  45. .padding(.vertical, 11)
  46. }
  47. }