forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIconToggleStyle.swift
More file actions
59 lines (51 loc) · 1.59 KB
/
IconToggleStyle.swift
File metadata and controls
59 lines (51 loc) · 1.59 KB
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
//
// IconToggleStyle.swift
// CodeEdit
//
// Created by Austin Condiff on 11/9/23.
//
import SwiftUI
struct IconToggleStyle: ToggleStyle {
var font: Font?
var size: CGSize?
@State var isPressing = false
init(font: Font? = nil, size: CGFloat? = nil) {
self.font = font
self.size = size == nil ? nil : CGSize(width: size ?? 0, height: size ?? 0)
}
init(font: Font? = nil, size: CGSize? = nil) {
self.font = font
self.size = size
}
init(font: Font? = nil) {
self.font = font
self.size = nil
}
func makeBody(configuration: ToggleStyle.Configuration) -> some View {
Button(
action: { configuration.isOn.toggle() },
label: { configuration.label }
)
.buttonStyle(.icon(isActive: configuration.isOn, font: font, size: size))
}
}
extension ToggleStyle where Self == IconToggleStyle {
static func icon(
font: Font? = Font.system(size: 14.5, weight: .regular, design: .default),
size: CGFloat? = 24
) -> IconToggleStyle {
return IconToggleStyle(font: font, size: size)
}
static func icon(
font: Font? = Font.system(size: 14.5, weight: .regular, design: .default),
size: CGSize? = CGSize(width: 24, height: 24)
) -> IconToggleStyle {
return IconToggleStyle(font: font, size: size)
}
static func icon(
font: Font? = Font.system(size: 14.5, weight: .regular, design: .default)
) -> IconToggleStyle {
return IconToggleStyle(font: font)
}
static var icon: IconToggleStyle { .init() }
}