Mercurial > public > geoquiz
comparison GeoQuiz/Helpers/GameButton.swift @ 26:425078c01194
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 09 Nov 2022 10:30:01 +0100 |
parents | GeoQuiz/Components/GameButton.swift@e281791e0494 |
children |
comparison
equal
deleted
inserted
replaced
25:b3df0f5dc750 | 26:425078c01194 |
---|---|
1 // | |
2 // GameButton.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 5/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct GameButton: View { | |
11 let gameInfo: GameInfo | |
12 let isActive: Bool | |
13 | |
14 init(gameType: GameType, isActive: Bool) { | |
15 self.gameInfo = GameInfoModel.getInfo(for: gameType) | |
16 self.isActive = isActive | |
17 } | |
18 | |
19 var body: some View { | |
20 RoundedRectangle(cornerRadius: 20) | |
21 .fill( | |
22 LinearGradient( | |
23 gradient: gameInfo.gradient, | |
24 startPoint: .trailing, endPoint: .leading | |
25 ) | |
26 ) | |
27 .frame(height: 180) | |
28 .frame(maxWidth: 700) | |
29 .overlay { | |
30 ZStack(alignment: .trailing) { | |
31 VStack(alignment: .leading) { | |
32 HStack { | |
33 Image(systemName: isActive ? gameInfo.symbol : "lock.fill") | |
34 .font(.headline) | |
35 .padding(5) | |
36 .background( | |
37 RoundedRectangle(cornerRadius: 5) | |
38 .stroke(lineWidth: 1.5) | |
39 ) | |
40 | |
41 Spacer() | |
42 } | |
43 .padding(.bottom) | |
44 | |
45 VStack(alignment: .leading, spacing: 5) { | |
46 Text(gameInfo.level) | |
47 .font(.callout) | |
48 | |
49 Text(gameInfo.name) | |
50 .font(.title.bold()) | |
51 } | |
52 } | |
53 .foregroundColor(.white) | |
54 .padding() | |
55 } | |
56 } | |
57 } | |
58 } | |
59 | |
60 struct GameButton_Previews: PreviewProvider { | |
61 static var previews: some View { | |
62 GameButton(gameType: .guessTheFlag, isActive: false) | |
63 } | |
64 } |