Advertisement
radicaldeepscale

List with NavigationLink

Aug 17th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 7.09 KB | Science | 0 0
  1. struct RNode: Hashable, Identifiable {
  2.     let id = UUID()
  3.     let title: String
  4.     let icon: String
  5.     var nodes: [RNode]?
  6.    
  7.    
  8.     //DART Meadow
  9.    
  10.     //Jounal
  11.    
  12.     //Research
  13.     static let elements = RNode(title: "Elements", icon: "flame")
  14.     static let sigcothian = RNode(title: "Sigcothian", icon: "star")
  15.     static let dartedge = RNode(title: "DART Edge", icon: "star")
  16.     static let orbit = RNode(title: "Orbit", icon: "star")
  17.     static let mass = RNode(title: "Mass", icon: "star")
  18.     static let volume = RNode(title: "Volume", icon: "star")
  19.     static let weight = RNode(title: "Weight", icon: "star")
  20.     static let density = RNode(title: "Density", icon: "star")
  21.     static let atm26 = RNode(title: "ATM 26", icon: "star")
  22.     static let breakvelocity = RNode(title: "Break | Velocity", icon: "star")
  23.     static let gas = RNode(title: "Gas", icon: "star")
  24.     static let liquid = RNode(title: "Liquid", icon: "star")
  25.     static let solid = RNode(title: "Solid", icon: "star")
  26.     static let crystalline = RNode(title: "Crystalline", icon: "star")
  27.     static let solartalatm = RNode(title: "Solartal ATM", icon: "star")
  28.     static let nozzle = RNode(title: "Nozzle", icon: "star")
  29.     static let decibel = RNode(title: "Decibel", icon: "star")
  30.     static let catalyst = RNode(title: "Catalyst", icon: "star")
  31.     static let phedge = RNode(title: "PH Edge", icon: "star")
  32.     static let bioedge = RNode(title: "BioEdge", icon: "star")
  33.     static let stealthedge = RNode(title: "StealthEdge", icon: "star")
  34.    
  35.     //Navagation
  36.    
  37.     //Logistics
  38.    
  39.     //Simulations
  40.     /*
  41.         .init(id: 1, title: "DART Meadow", imageName: "sun.max.fill"),
  42.         .init(id: 2, title: "Journal", imageName: "note.text"),
  43.         .init(id: 3, title: "Research", imageName: "flame"),
  44.         .init(id: 4, title: "Navigation", imageName: "moon.stars.fill"),
  45.         .init(id: 5, title: "Logistics", imageName: "cube.transparent.fill"),
  46.         .init(id: 6, title: "Simulations", imageName: "chart.pie.fill"),
  47.      */
  48.     // subcontent
  49.     static let dartmeadow = RNode(title: "DART Meadow", icon: "star")
  50.     static let research = RNode(title: "Research", icon: "star", nodes: [RNode.elements, RNode.sigcothian, RNode.dartedge, RNode.orbit, RNode.mass, RNode.volume, RNode.weight, RNode.density, RNode.atm26, RNode.breakvelocity, RNode.gas, RNode.liquid, RNode.solid, RNode.crystalline, RNode.solartalatm, RNode.nozzle, RNode.decibel, RNode.catalyst, RNode.phedge, RNode.bioedge, RNode.stealthedge])
  51.    
  52. }
  53. enum DraggableState {
  54.     case inactive
  55.     case pressing
  56.     case dragging(translation: CGSize)
  57.    
  58.     var translation: CGSize {
  59.         switch self {
  60.         case .inactive, .pressing:
  61.             return .zero
  62.         case .dragging(let translation):
  63.             return translation
  64.         }
  65.     }
  66.    
  67.     var isPressing: Bool {
  68.         switch self {
  69.         case .pressing, .dragging:
  70.             return true
  71.         case .inactive:
  72.             return false
  73.         }
  74.     }
  75. }
  76.  
  77.  
  78.    
  79.        
  80. struct ContentMenu: View {
  81.     @GestureState private var dragState = DraggableState.inactive
  82.     @State private var position = CGSize.zero
  83.     let nodes: [RNode] = [.dartmeadow,.research]
  84.     /*#-code-walkthrough(2.columnLayout)*/
  85.     let columnLayout = Array(repeating: GridItem(), count: 1)
  86.    
  87.     /*
  88.     let allColors: [Color] = [
  89.         .pink,
  90.         .red,
  91.         .orange,
  92.         .yellow,
  93.         .green,
  94.         .mint,
  95.         .teal,
  96.         .cyan,
  97.         .blue,
  98.         .indigo,
  99.         .purple,
  100.         .brown,
  101.         .gray
  102.     ]
  103.      */
  104.    
  105.    
  106.     var body: some View {
  107.         VStack(alignment: .leading) {
  108.         HStack(alignment: .top) {
  109.         VStack(alignment: .center) {
  110.             Image("Cotharticren60")
  111.             .font(.system(size: 28))
  112.             //.bold()
  113.             .opacity(dragState.isPressing ? 0.5 : 1.0)
  114.             .offset(x: position.width + dragState.translation.width, y: position.height + dragState.translation.height)
  115.             .animation(.easeInOut, value: dragState.translation)
  116.             .foregroundColor(.blue)
  117.             .gesture(
  118.                 LongPressGesture(minimumDuration: 0.5)
  119.                     .sequenced(before: DragGesture())
  120.                     .updating($dragState, body: { (value, state, transaction) in
  121.                        
  122.                         switch value {
  123.                         case .first(true):
  124.                             state = .pressing
  125.                         case .second(true, let drag):
  126.                             state = .dragging(translation: drag?.translation ?? .zero)
  127.                         default:
  128.                             break
  129.                         }
  130.                        
  131.                     })
  132.                     .onEnded({ (value) in
  133.                        
  134.                         guard case .second(true, let drag?) = value else {
  135.                             return
  136.                         }
  137.                        
  138.                         self.position.height += drag.translation.height
  139.                         self.position.width += drag.translation.width
  140.                     })
  141.             )
  142.         }
  143.         }.frame(
  144.             maxWidth: .infinity,
  145.             maxHeight: 100, alignment: .center).background(.red)
  146.        
  147.             VStack(alignment: .center) {
  148.                     List(nodes, children: \.nodes) { row in
  149.                         ZStack(alignment: .leading){
  150.                             RoundedRectangle(cornerRadius: 4.0)
  151.                                 .aspectRatio(4.5, contentMode: ContentMode.fit)
  152.                                 .foregroundColor(.blue)
  153.                                 .shadow(radius: 3)
  154.                             HStack(alignment: .center){
  155.                                 Image(systemName: row.icon).padding(.leading, 8).padding(.trailing, 8)
  156.                                 Text(row.title)
  157.                                
  158.                                 NavigationLink(destination: DETEView()) {
  159.                                     Text(RNode.elements)
  160.                                 }
  161.                                 NavigationLink(destination: SigcothianView()) {
  162.                                     Text(RNode.sigcothian)
  163.                                 }
  164.                                 NavigationLink(destination: DARTEdge()) {
  165.                                     Text(RNode.dartedge)
  166.                                 }
  167.                                
  168.                                
  169.                             }
  170.                         }
  171.                 /*
  172.                     .onTapGesture {
  173.                         //self.selectedItem = RNode.node
  174.                     }
  175.                  */
  176.            
  177.             }.onAppear {
  178.                 // Set the default to clear
  179.                 UITableView.appearance().backgroundColor = .clear
  180.             }
  181.             }
  182.         }.frame(
  183.             maxWidth: .infinity,
  184.             maxHeight: .infinity, alignment: .leading)
  185.         .background(.gray)
  186.            
  187.        
  188.        
  189.        
  190.     }
  191.    
  192. }
  193.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement