parent
0feb38d604
commit
ab009dbb0c
@ -0,0 +1,65 @@
|
||||
//
|
||||
// DoushiQiPicker.swift
|
||||
// ArkitDoushiQi
|
||||
//
|
||||
// Created by Johan LACHENAL on 21/05/2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum AI: String, CaseIterable, Identifiable, Hashable {
|
||||
case RandomAction = "IA Random"
|
||||
case EasyTrainedAI = "IA Facile"
|
||||
case MediumTrainedAI = "IA Intermédiaire"
|
||||
|
||||
var id: String { self.rawValue }
|
||||
}
|
||||
|
||||
struct DoushiQiPicker<EnumType: RawRepresentable & CaseIterable & Identifiable & Hashable>: View where EnumType.RawValue == String, EnumType.AllCases: RandomAccessCollection {
|
||||
let title: String
|
||||
@Binding var selectedOption: EnumType
|
||||
|
||||
init(title: String, selectedOption: Binding<EnumType>) {
|
||||
self.title = title
|
||||
self._selectedOption = selectedOption
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
Picker(title, selection: $selectedOption) {
|
||||
ForEach(EnumType.allCases) { option in
|
||||
Text(option.rawValue.description)
|
||||
.tag(option)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.pickerStyle(InlinePickerStyle())
|
||||
} label: {
|
||||
HStack {
|
||||
Text(title)
|
||||
.foregroundColor(.white)
|
||||
.padding()
|
||||
Spacer()
|
||||
Text(selectedOption.rawValue.description)
|
||||
.foregroundColor(.white)
|
||||
.padding()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(EdgeInsets(top: 10, leading: 32, bottom: 10, trailing: 32))
|
||||
.background(Color.black)
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DoushiQiPicker_Previews: PreviewProvider {
|
||||
@State static var selectedItem = AI.RandomAction
|
||||
|
||||
static var previews: some View {
|
||||
DoushiQiPicker(title: "Selectionne une IA :", selectedOption: $selectedItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
/
|
||||
// Picker.swift
|
||||
// ArkitDoushiQi
|
||||
//
|
||||
// Created by Johan LACHENAL on 21/05/2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct Picker: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct Picker_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Picker()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue