GradeMapper/Shared/ContentView.swift

75 lines
1.8 KiB
Swift
Raw Normal View History

2022-01-18 16:39:08 +03:00
//
2022-01-18 20:23:35 +03:00
// SubjectView.swift
// GradeMapper
2022-01-18 16:39:08 +03:00
//
2022-01-18 20:23:35 +03:00
// Created by Иван Бущик on 18.01.2022.
2022-01-18 16:39:08 +03:00
//
import SwiftUI
2022-01-18 20:23:35 +03:00
enum Grade: Int, Identifiable, CaseIterable{
case One = 1
case Two = 2
case Three = 3
case Four = 4
case Five = 5
2022-01-18 16:39:08 +03:00
2022-01-18 20:23:35 +03:00
var id: Int { self.rawValue }
}
struct ContentView: View {
var counter = counters()
@State var sr: Double = 0
@State private var selectedGrade = Grade.One
@State var selectedTypeOfGrade = "Контрольная работа"
var body: some View {
Text("GradeMapper")
.font(.largeTitle)
.fontWeight(.heavy)
.multilineTextAlignment(.center)
.padding(.top, -75)
VStack(alignment: .center, spacing: 75){
VStack(alignment: .leading, spacing: 30){
Picker("Тип оценки", selection: $selectedTypeOfGrade){
ForEach([String](coof.keys), id: \.self) {
subjectSN in Text("\(subjectSN)")
}
2022-01-18 20:29:03 +03:00
}
.pickerStyle(.wheel)
2022-01-18 20:23:35 +03:00
VStack{
Picker("Оценка", selection: $selectedGrade){
ForEach(Grade.allCases, id: \.self) {
currGrade in Text("\(currGrade.rawValue)")
}
2022-01-18 16:39:08 +03:00
}
2022-01-18 20:29:03 +03:00
}
.pickerStyle(.segmented)
.padding(.horizontal, 20)
}
.padding(.top, 100)
2022-01-18 20:23:35 +03:00
Button ("Добавить оценку"){
counter.multiplier = coof[selectedTypeOfGrade]!
counter.gradesWeighted += Double(selectedGrade.rawValue) * counter.multiplier
counter.weightsSum += counter.multiplier
self.sr = (counter.gradesWeighted / counter.weightsSum)
2022-01-18 20:29:03 +03:00
}
.buttonStyle(.borderedProminent)
Text(String("Средний балл: \(self.sr)"))
.fontWeight(.bold)
2022-01-18 20:23:35 +03:00
Button ("Очистить"){
counter.multiplier = 1.5
counter.gradesWeighted = 0
counter.weightsSum = 0
self.sr = 0
}.buttonStyle(.borderedProminent)
}
2022-01-18 20:29:03 +03:00
.padding(.top, -155.0)
2022-01-18 16:39:08 +03:00
}
}
struct ContentView_Previews: PreviewProvider {
2022-01-18 20:23:35 +03:00
static var previews: some View {
2022-01-18 16:39:08 +03:00
ContentView()
}
}