Mercurial > public > geoquiz
annotate GeoQuiz/Components/GameButton.swift @ 21:b145c408f791
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 25 Oct 2022 15:30:01 +0200 |
parents | e281791e0494 |
children |
rev | line source |
---|---|
0 | 1 // |
20 | 2 // GameButton.swift |
0 | 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 { | |
19 | 11 let gameInfo: GameInfo |
12 let isActive: Bool | |
13 | |
14 init(gameType: GameType, isActive: Bool) { | |
15 self.gameInfo = GameInfoController.getInfo(for: gameType) | |
16 self.isActive = isActive | |
17 } | |
0 | 18 |
19 var body: some View { | |
11 | 20 RoundedRectangle(cornerRadius: 20) |
21 .fill( | |
22 LinearGradient( | |
19 | 23 gradient: gameInfo.gradient, |
11 | 24 startPoint: .trailing, endPoint: .leading |
0 | 25 ) |
11 | 26 ) |
27 .frame(height: 180) | |
28 .frame(maxWidth: 700) | |
29 .overlay { | |
30 ZStack(alignment: .trailing) { | |
31 VStack(alignment: .leading) { | |
32 HStack { | |
19 | 33 Image(systemName: isActive ? gameInfo.symbol : "lock.fill") |
11 | 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) { | |
19 | 46 Text(gameInfo.level) |
11 | 47 .font(.callout) |
48 | |
19 | 49 Text(gameInfo.name) |
11 | 50 .font(.title.bold()) |
51 } | |
52 } | |
53 .foregroundColor(.white) | |
54 .padding() | |
0 | 55 } |
56 } | |
57 } | |
58 } | |
59 | |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
60 struct GameButton_Previews: PreviewProvider { |
0 | 61 static var previews: some View { |
19 | 62 GameButton(gameType: .guessTheFlag, isActive: false) |
0 | 63 } |
64 } |