41 lines
959 B
Swift
41 lines
959 B
Swift
//
|
|
// RerollPickerView.swift
|
|
// Bunch O' Dice
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct RerollPickerView: View {
|
|
@EnvironmentObject var current: Roll
|
|
@Binding var mode: RerollMode
|
|
|
|
var body: some View {
|
|
let actionBinding = Binding<RerollMode>(
|
|
get: { mode },
|
|
set: { newValue in
|
|
mode = newValue
|
|
if newValue != .none {
|
|
current.applyReroll()
|
|
} else {
|
|
current.undoReroll()
|
|
}
|
|
}
|
|
)
|
|
HStack(spacing: 8) {
|
|
Text("Reroll")
|
|
Picker("Reroll", selection: actionBinding) {
|
|
ForEach(RerollMode.allCases, id: \.self) { m in
|
|
Text(m.label).tag(m)
|
|
}
|
|
}
|
|
.pickerStyle(.segmented)
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
RerollPickerView(mode: .constant(.none))
|
|
.environmentObject(Roll())
|
|
}
|