From b6932a739f91adb1775f2794138d2c86f801b78c Mon Sep 17 00:00:00 2001 From: Benedikt Wagner Date: Mon, 3 Jun 2024 13:19:37 +0700 Subject: [PATCH] fix button width for question choice, improve design --- .../Features/Exam/Views/ExamView.swift | 27 +++++--- .../Training/Views/TrainingView.swift | 66 ++++++++++++------- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/CloudMaster/Features/Exam/Views/ExamView.swift b/CloudMaster/Features/Exam/Views/ExamView.swift index b686900..0c17c8b 100644 --- a/CloudMaster/Features/Exam/Views/ExamView.swift +++ b/CloudMaster/Features/Exam/Views/ExamView.swift @@ -69,11 +69,12 @@ struct ExamView: View { }) { Text(currentQuestionIndex < questions.count - 1 ? "Next Question" : "Show Exam Result") .padding() + .frame(maxWidth: .infinity) .background(Color.customSecondary) .foregroundColor(.white) .cornerRadius(10) } - .padding() + .padding(.horizontal, 20) Spacer() @@ -179,6 +180,8 @@ struct ExamQuestion: View { .lineLimit(nil) // Allow text to wrap as needed .fixedSize(horizontal: false, vertical: true) .padding(.horizontal) + .frame(alignment: .leading) + .multilineTextAlignment(.center) if let imagePath = question.imagePath, let image = loadImage(from: imagePath) { @@ -232,15 +235,19 @@ struct ExamChoice: View { let onChoiceSelected: (UUID) -> Void var body: some View { - Text(choice.text) - .padding() - .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) - .background(isSelected ? Color.blue.opacity(0.3) : Color.clear) - .cornerRadius(10) - .onTapGesture { - onChoiceSelected(choice.id) - } - .multilineTextAlignment(.center) + Button(action: { + onChoiceSelected(choice.id) + }) { + Text(choice.text) + .padding() + .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) + .multilineTextAlignment(.center) + } + .background(isSelected ? Color.gray.opacity(0.3) : Color.clear) + .cornerRadius(10) + .padding(.horizontal) + .foregroundColor(.white) + Divider() } } diff --git a/CloudMaster/Features/Training/Views/TrainingView.swift b/CloudMaster/Features/Training/Views/TrainingView.swift index 5c97899..8b2720f 100644 --- a/CloudMaster/Features/Training/Views/TrainingView.swift +++ b/CloudMaster/Features/Training/Views/TrainingView.swift @@ -47,17 +47,36 @@ struct TrainingView: View { HStack(spacing: 20) { if !showResult { - Button(action: { - showResult = true - updateUserTrainingData(for: question) - }) { - Text("Show Result") - .padding(10) - .background(Color.customPrimary) - .foregroundColor(.white) - .cornerRadius(10) - } - } else { + if currentQuestionIndex > 0 { + Button(action: { + currentQuestionIndex = max(currentQuestionIndex - 1, 0) + selectedChoices.removeAll() + showResult = false + startTime = Date() + }) { + Text("Previous") + .padding(10) + .frame(maxWidth: .infinity) + .background(Color.customSecondary) + .foregroundColor(.white) + .cornerRadius(10) + } + } else { + Spacer() + } + + Button(action: { + showResult = true + updateUserTrainingData(for: question) + }) { + Text("Show Result") + .padding(10) + .frame(maxWidth: .infinity) + .background(Color.customPrimary) + .foregroundColor(.white) + .cornerRadius(10) + } + } else { Button(action: { currentQuestionIndex = (currentQuestionIndex + 1) % totalQuestions selectedChoices.removeAll() @@ -66,6 +85,7 @@ struct TrainingView: View { }) { Text("Next Question") .padding(10) + .frame(maxWidth: .infinity) .background(Color.customSecondary) .foregroundColor(.white) .cornerRadius(10) @@ -209,16 +229,19 @@ struct TrainingChoice: View { let onChoiceSelected: (UUID) -> Void var body: some View { - Text(choice.text) - .padding() - .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) - .background(getChoiceBackgroundColor()) - .foregroundColor(getChoiceTextColor()) - .cornerRadius(10) - .onTapGesture { - onChoiceSelected(choice.id) - } - .multilineTextAlignment(.center) + Button(action: { + onChoiceSelected(choice.id) + }) { + Text(choice.text) + .padding() + .frame(minWidth: 0, maxWidth: .infinity, alignment: .center) + .multilineTextAlignment(.center) + } + .background(getChoiceBackgroundColor()) + .foregroundColor(getChoiceTextColor()) + .cornerRadius(10) + .padding(.horizontal) + .disabled(isResultShown) Divider() } @@ -243,5 +266,4 @@ struct TrainingChoice: View { return .primary } } - }