More cleaning, added min width of cards and scrollable if too many cards are on the screen

This commit is contained in:
2023-04-16 14:31:40 +02:00
parent 8836411c6b
commit 6d72b59426
3 changed files with 26 additions and 13 deletions

View File

@@ -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
} }
} }

View File

@@ -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
} }

View File

@@ -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)
}
}
}
}
}
}
} }