import SwiftUI
// โญ๏ธ ๅฏ่ช่จๆจ้กใ็พๅๆฏใ้ฒๅบฆๆขๆจฃๅผ
public struct NeuProgressBar2<Bar: View>: View {
var title: String // ้ฒๅบฆๆขใๆจ้กใ
let bar : Bar // ้ฒๅบฆๆขใๆจฃๅผใ
@Binding var percent: CGFloat // ้ฒๅบฆๆขใๆจฃ็พๅๆฏใ
// NeuProgressBar2(title:percent:bar:)
public init(
title : String,
percent: Binding<CGFloat>,
@ViewBuilder bar: () -> Bar // โญ๏ธ ViewBuilder closure
) {
self._percent = percent // โญ๏ธ ๅณ้ฒ @Binding ่ฎๆธ็ๆนๅผ
self.title = title
self.bar = bar()
}
public var body: some View {
VStack {
// title & percentage
NeuProgressBarTitle(title: self.title, percent: self.$percent)
// progress bar
MyProgressBar2(self.$percent) { self.bar }
}
}
}
// โญ๏ธ ็ตฆ้ฒๅบฆๆขใ้ ่จญๆจฃๅผใ
extension NeuProgressBar2 where Bar == LinearGradient {
// NeuProgressBar2(title:percent:)
public init(
title : String,
percent: Binding<CGFloat>
) {
self._percent = percent // โญ๏ธ ๅณ้ฒ @Binding ่ฎๆธ
self.title = title
// โญ๏ธ ็ตฆ้ฒๅบฆๆขใ้ ่จญๆจฃๅผใ
self.bar = Gradient.right(Color.yellow.opacity(0.8), .red) as! Bar
}
}