Runt
2025-07-09 3b7521a47ae731f0bf0a922822e4417493489539
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
//  Untitled.swift
//  LiveProject
//
//  Created by 倪路朋 on 6/25/25.
//
 
 
import SwiftUI
 
struct MButton: View {
    
    var valid :ValidState = .VALID;
    
    var icon : IconInfo? = nil;
    
    var text : String? = nil;
    
    var onClick : () -> Void = {
        
    }
    
    var body: some View {
        Button(action: {
            if(valid == .INVALID){
                return
            }
            onClick();
        }) {
            
            ZStack() {// iOS
                HStack() {// iOS
                    if let info = icon{
                        Image(systemName: info.name)
                            .resizable()
                            .frame(width: info.size.width, height: info.size.height)
                            .aspectRatio(contentMode: .fit)
                            .foregroundColor(Color.white)
                    }
                    if let str = text {
                        Text(str)
                            .font(Font.system(size: 16))
                            .foregroundColor(Color.white)
                            .frame(width: .infinity, height: 40)
                    }
                }.frame(minWidth: 40, maxHeight: 40).padding(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
            }.frame(maxHeight: 40).background(
                RoundedRectangle(cornerRadius: 20, style: .continuous)
                    .fill(valid == .INVALID ? Color.colorGray : Color.colorText)
            )
            
        }.buttonStyle( TextBtnStyle())
    }
}
 
struct MButton_Previews: PreviewProvider {
    static var previews: some View {
        MButton(icon: Icons.IMAGE_MUTE)
    }
}