More cleaning, added min width of cards and scrollable if too many cards are on the screen
This commit is contained in:
		| @@ -132,7 +132,6 @@ struct SetGame { | |||||||
|         static let numberOfDifferences = 4 |         static let numberOfDifferences = 4 | ||||||
|         static let cardsOnTableInTheBeggining = 12 |         static let cardsOnTableInTheBeggining = 12 | ||||||
|         static let numberOfCardsToDraw = 3 |         static let numberOfCardsToDraw = 3 | ||||||
|          |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,13 +19,6 @@ class SetGameModelView: ObservableObject { | |||||||
|     } |     } | ||||||
|      |      | ||||||
|     var cardsOnTable: Array<Card> { |     var cardsOnTable: Array<Card> { | ||||||
| //        var cardsOnTable: Array<Card> = Array() |  | ||||||
| //        for card in model.cards { |  | ||||||
| //            if (card.isOnTheTable && !card.isMatched) { |  | ||||||
| //                cardsOnTable.append(card) |  | ||||||
| //            } |  | ||||||
| //        } |  | ||||||
| //        return cardsOnTable |  | ||||||
|         model.displayedCards |         model.displayedCards | ||||||
|     } |     } | ||||||
|      |      | ||||||
|   | |||||||
| @@ -12,11 +12,7 @@ struct SetGameView: View { | |||||||
|     @ObservedObject var game: SetGameModelView |     @ObservedObject var game: SetGameModelView | ||||||
|     var body: some View { |     var body: some View { | ||||||
|         VStack { |         VStack { | ||||||
|             AspectVGrid(items: game.cardsOnTable, aspectRatio: 2/3) { card in |             ScrollOrAspectVGrid() | ||||||
|                 CardView(card: card).foregroundColor(.red).onTapGesture { |  | ||||||
|                     game.choose(card) |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             Spacer() |             Spacer() | ||||||
|             Spacer() |             Spacer() | ||||||
|             VStack { |             VStack { | ||||||
| @@ -30,6 +26,31 @@ struct SetGameView: View { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     @ViewBuilder | ||||||
|  |     private func ScrollOrAspectVGrid() -> some View { | ||||||
|  |         if (game.cardsOnTable.count <= 21) { | ||||||
|  |                 AspectVGrid(items: game.cardsOnTable, aspectRatio: 2/3) { card in | ||||||
|  |                     CardView(card: card).foregroundColor(.red).onTapGesture { | ||||||
|  |                         game.choose(card) | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             ScrollView { | ||||||
|  |                 LazyVGrid(columns: [GridItem(.adaptive(minimum: 70), spacing: 0)], spacing: 0) { | ||||||
|  |                     ForEach(game.cardsOnTable) { card in | ||||||
|  |                         CardView(card: card) | ||||||
|  |                             .aspectRatio(2/3, contentMode: .fit) | ||||||
|  |                             .foregroundColor(.red) | ||||||
|  |                             .onTapGesture { | ||||||
|  |                             game.choose(card) | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user