TabPosition.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // LoopFollow
  2. // TabPosition.swift
  3. enum TabPosition: String, CaseIterable, Codable, Comparable {
  4. case position1
  5. case position2
  6. case position3
  7. case position4
  8. case menu
  9. case more
  10. case disabled
  11. var displayName: String {
  12. switch self {
  13. case .position1: return "Tab 1"
  14. case .position2: return "Tab 2"
  15. case .position3: return "Tab 3"
  16. case .position4: return "Tab 4"
  17. case .menu, .more, .disabled: return "Menu"
  18. }
  19. }
  20. /// The index in the tab bar (0-based)
  21. var tabIndex: Int? {
  22. switch self {
  23. case .position1: return 0
  24. case .position2: return 1
  25. case .position3: return 2
  26. case .position4: return 3
  27. case .menu, .more, .disabled: return 4
  28. }
  29. }
  30. /// Positions that users can customize (1-4)
  31. static var customizablePositions: [TabPosition] {
  32. [.position1, .position2, .position3, .position4]
  33. }
  34. /// Normalize legacy values to current values
  35. var normalized: TabPosition {
  36. switch self {
  37. case .more, .disabled: return .menu
  38. default: return self
  39. }
  40. }
  41. // Comparable conformance for sorting
  42. static func < (lhs: TabPosition, rhs: TabPosition) -> Bool {
  43. let order: [TabPosition] = [.position1, .position2, .position3, .position4, .menu, .more, .disabled]
  44. guard let lhsIndex = order.firstIndex(of: lhs),
  45. let rhsIndex = order.firstIndex(of: rhs) else { return false }
  46. return lhsIndex < rhsIndex
  47. }
  48. }
  49. /// Represents a tab item that can be placed in any position
  50. enum TabItem: String, CaseIterable, Codable, Identifiable {
  51. case home
  52. case alarms
  53. case remote
  54. case nightscout
  55. case snoozer
  56. case treatments
  57. case stats
  58. var id: String { rawValue }
  59. var displayName: String {
  60. switch self {
  61. case .home: return "Home"
  62. case .alarms: return "Alarms"
  63. case .remote: return "Remote"
  64. case .nightscout: return "Nightscout"
  65. case .snoozer: return "Snoozer"
  66. case .treatments: return "Treatments"
  67. case .stats: return "Statistics"
  68. }
  69. }
  70. var icon: String {
  71. switch self {
  72. case .home: return "house"
  73. case .alarms: return "alarm"
  74. case .remote: return "antenna.radiowaves.left.and.right"
  75. case .nightscout: return "safari"
  76. case .snoozer: return "zzz"
  77. case .treatments: return "cross.case"
  78. case .stats: return "chart.bar.xaxis"
  79. }
  80. }
  81. /// Items that can be moved between tab bar and menu (all except settings which doesn't exist as a tab)
  82. static var movableItems: [TabItem] {
  83. [.home, .alarms, .remote, .nightscout, .snoozer, .treatments, .stats]
  84. }
  85. }