forked from AcaMate/AcaMate_iOS
52 lines
1.4 KiB
Swift
52 lines
1.4 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.title, let font = state.font {
|
|
Text("\(title)")
|
|
.font(font)
|
|
.lineLimit(1)
|
|
.minimumScaleFactor(0.5)
|
|
.multilineTextAlignment(.center)
|
|
.truncationMode(.tail)
|
|
.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()
|
|
.frame(width: state.width, height: state.height)
|
|
}
|
|
}
|
|
.disabled(!state.isUsable)
|
|
}
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
}
|