@@ -24,20 +24,39 @@ public struct CircularControl<Label: View, TrackStyle: ShapeStyle, ProgressStyle
2424 public init (
2525 progress: Double ,
2626 isEditable: Bool = false ,
27- strokeWidth: CGFloat = 20 ,
27+ strokeWidth: CGFloat = . defaultStrokeWidth ,
2828 style: CircularControlStyle < TrackStyle , ProgressStyle , KnobStyle > = . init( ) ,
2929 onProgressChange: ( ( Double ) -> Void ) ? = nil ,
3030 @ViewBuilder label: ( ) -> Label
3131 ) {
32- self . progress = progress. clamped ( to: 0 ... 1 )
33- self . _currentProgress = State ( initialValue: progress. clamped ( to: 0 ... 1 ) )
32+ let initialProgress = progress. clamped ( to: 0 ... 1 )
33+ self . progress = initialProgress
34+ self . _currentProgress = State ( initialValue: initialProgress)
3435 self . isEditable = isEditable
3536 self . strokeWidth = strokeWidth
3637 self . strokeStyle = style
3738 self . onProgressChange = onProgressChange
3839 self . label = label ( )
3940 }
4041
42+ public init (
43+ progress: Binding < Double > ,
44+ strokeWidth: CGFloat = . defaultStrokeWidth,
45+ style: CircularControlStyle < TrackStyle , ProgressStyle , KnobStyle > = . init( ) ,
46+ @ViewBuilder label: ( ) -> Label
47+ ) {
48+ let initialProgress = progress. wrappedValue. clamped ( to: 0 ... 1 )
49+ self . progress = initialProgress
50+ self . _currentProgress = State ( initialValue: initialProgress)
51+ self . isEditable = true
52+ self . strokeWidth = strokeWidth
53+ self . strokeStyle = style
54+ self . onProgressChange = { newValue in
55+ progress. wrappedValue = newValue. clamped ( to: 0 ... 1 )
56+ }
57+ self . label = label ( )
58+ }
59+
4160 public var body : some View {
4261 Track (
4362 progress: currentProgress,
@@ -61,11 +80,11 @@ public struct CircularControl<Label: View, TrackStyle: ShapeStyle, ProgressStyle
6180
6281// MARK: - Default Label Convenience Initializer
6382
64- public extension CircularControl where Label == DefaultLabel {
65- init (
83+ extension CircularControl where Label == DefaultLabel {
84+ public init (
6685 progress: Double ,
6786 isEditable: Bool = false ,
68- strokeWidth: CGFloat = 20 ,
87+ strokeWidth: CGFloat = . defaultStrokeWidth ,
6988 style: CircularControlStyle < TrackStyle , ProgressStyle , KnobStyle > = . init( ) ,
7089 format: DefaultLabelFormat = . percentage,
7190 onProgressChange: ( ( Double ) -> Void ) ? = nil
@@ -80,6 +99,26 @@ public extension CircularControl where Label == DefaultLabel {
8099 DefaultLabel ( format: format)
81100 }
82101 }
102+
103+ public init (
104+ progress: Binding < Double > ,
105+ strokeWidth: CGFloat = . defaultStrokeWidth,
106+ style: CircularControlStyle < TrackStyle , ProgressStyle , KnobStyle > = . init( ) ,
107+ format: DefaultLabelFormat = . percentage
108+ ) {
109+ self . init (
110+ progress: progress,
111+ strokeWidth: strokeWidth,
112+ style: style
113+ ) {
114+ DefaultLabel ( format: format)
115+ }
116+ }
117+ }
118+
119+ extension CGFloat {
120+ @usableFromInline
121+ static let defaultStrokeWidth : CGFloat = 20
83122}
84123
85124// MARK: - Xcode Previews
0 commit comments