term-kit-backend/Sources/TermKitBackend/View/ProgressBar.swift

32 lines
690 B
Swift
Raw Normal View History

2024-07-10 14:41:11 +02:00
//
// ProgressBar.swift
// TermKitBackend
//
// Created by david-swift on 07.07.2024.
//
import TermKit
/// A simple progress bar view.
public struct ProgressBar: TermKitWidget {
/// The current value.
@Property(set: { $0.fraction = $1 }, pointer: TermKit.ProgressBar.self)
var fraction: Float = 0
2024-07-31 14:33:40 +02:00
2024-07-10 14:41:11 +02:00
/// Initialize a progress bar.
/// - Parameters:
/// - value: The current value.
/// - max: The maximum value.
public init(value: Double, max: Double = 1) {
self.fraction = .init(value / max)
2024-07-10 14:41:11 +02:00
}
/// Get the widget.
/// - Returns: The widget.
public func initializeWidget() -> Any {
TermKit.ProgressBar()
2024-07-10 14:41:11 +02:00
}
}