Skip to content

Commit

Permalink
Merge pull request #12 from Ditectrev/8-answer-option-is-clickable-on…
Browse files Browse the repository at this point in the history
…ly-on-width-of-text

fix button width for question choice #8
  • Loading branch information
danieldanielecki authored Jun 3, 2024
2 parents 8e9323d + b6932a7 commit ac85164
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 32 deletions.
27 changes: 17 additions & 10 deletions CloudMaster/Features/Exam/Views/ExamView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
}
66 changes: 44 additions & 22 deletions CloudMaster/Features/Training/Views/TrainingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -66,6 +85,7 @@ struct TrainingView: View {
}) {
Text("Next Question")
.padding(10)
.frame(maxWidth: .infinity)
.background(Color.customSecondary)
.foregroundColor(.white)
.cornerRadius(10)
Expand Down Expand Up @@ -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()
}
Expand All @@ -243,5 +266,4 @@ struct TrainingChoice: View {
return .primary
}
}

}

0 comments on commit ac85164

Please sign in to comment.