forked from AcaMate/AcaMate_iOS
51 lines
1.5 KiB
Swift
51 lines
1.5 KiB
Swift
//
|
|
// SimpleBtnView.swift
|
|
// AcaMate
|
|
//
|
|
// Created by TAnine on 2/4/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
//import combine
|
|
|
|
|
|
struct SimpleBtnView: View {
|
|
@ObservedObject var vm: ButtonViewModel
|
|
let id: UUID
|
|
|
|
var body: some View {
|
|
if let state = vm.btnStates[id] {
|
|
if let title = state.text, let font = state.font {
|
|
Text("\(title)")
|
|
.font(font)
|
|
.multilineStyle(.center)
|
|
.foregroundStyle(state.textColor)
|
|
.frame(width: state.width, height: state.height)
|
|
.onTapGesture {
|
|
if state.isUsable {
|
|
guard let action = state.action else { return }
|
|
action()
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
Button{
|
|
guard let action = state.action else { return }
|
|
action()
|
|
} label: {
|
|
if let image = state.image {
|
|
image
|
|
.resizable()
|
|
.renderingMode(.template)
|
|
.frame(width: state.width, height: state.height)
|
|
.foregroundStyle(state.isUsable ? Color(.Second.normal) : Color(.Normal.normal))
|
|
}
|
|
}
|
|
.disabled(!state.isUsable)
|
|
}
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
}
|