You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LeCountdown/LeCountdown/Views/SoundImageFormView.swift

89 lines
2.8 KiB

//
// SoundImageFormView.swift
// LeCountdown
//
// Created by Laurent Morvillier on 01/02/2023.
//
import SwiftUI
struct SoundImageFormView : View {
var imageBinding: Binding<CoolPic>
var soundBinding: Binding<Sound>
var repeatsBinding: Binding<Bool>? = nil
var optionalSound: Binding<Bool>? = nil
@State var imageSelectionSheetShown: Bool = false
var body: some View {
Group {
Section(header: Text("Properties")) {
if self.optionalSound != nil {
Toggle("Play sound on end", isOn: optionalSound!)
if self.optionalSound?.wrappedValue == true {
Picker(selection: soundBinding) {
ForEach(Sound.allCases) { sound in
Text(sound.localizedString).tag(sound)
}
} label: {
Text("Sound")
}
}
} else {
Picker(selection: soundBinding) {
ForEach(Sound.allCases) { sound in
Text(sound.localizedString).tag(sound)
}
} label: {
Text("Sound")
}
}
// if self.repeatsBinding != nil {
// Toggle("Sound repeats", isOn: repeatsBinding!)
// }
}
Section(header: Text("Background")) {
Button {
self.imageSelectionSheetShown = true
} label: {
Group {
if let image = self.imageBinding.wrappedValue {
Image(image.rawValue).resizable()
} else {
Image(imageBinding.wrappedValue.rawValue).resizable()
}
}
.font(Font.system(size: 90.0))
.aspectRatio(1, contentMode: .fit)
.frame(width: 100.0, height: 100.0)
.cornerRadius(20.0)
}
}
}.sheet(isPresented: self.$imageSelectionSheetShown) {
ImageSelectionView(showBinding: self.$imageSelectionSheetShown, imageBinding: self.imageBinding)
}
}
}
struct SoundImageFormView_Previews: PreviewProvider {
static var previews: some View {
Form {
SoundImageFormView(imageBinding: .constant(.pic1),
soundBinding: .constant(.trainhorn),
repeatsBinding: .constant(true))
}
}
}