Add support for GtkProgressBar
This commit is contained in:
parent
4f876fa4c8
commit
bd2687b4d1
@ -35,6 +35,7 @@
|
||||
- [NavigationSplitView](structs/NavigationSplitView.md)
|
||||
- [Overlay](structs/Overlay.md)
|
||||
- [OverlaySplitView](structs/OverlaySplitView.md)
|
||||
- [ProgressBar](structs/ProgressBar.md)
|
||||
- [ScrollView](structs/ScrollView.md)
|
||||
- [Signal](structs/Signal.md)
|
||||
- [State](structs/State.md)
|
||||
|
||||
@ -120,6 +120,12 @@ Run a function when the view gets an update.
|
||||
- Parameter onUpdate: The function.
|
||||
- Returns: A view.
|
||||
|
||||
### `insensitive(_:)`
|
||||
|
||||
Make the view insensitive (useful e.g. in overlays).
|
||||
- Parameter insensitive: Whether the view is insensitive.
|
||||
- Returns: A view.
|
||||
|
||||
### `stopModifiers()`
|
||||
|
||||
Remove all of the content modifiers for the wrapped views.
|
||||
|
||||
30
Documentation/Reference/structs/ProgressBar.md
Normal file
30
Documentation/Reference/structs/ProgressBar.md
Normal file
@ -0,0 +1,30 @@
|
||||
**STRUCT**
|
||||
|
||||
# `ProgressBar`
|
||||
|
||||
A progress bar widget.
|
||||
|
||||
## Properties
|
||||
### `value`
|
||||
|
||||
The value.
|
||||
|
||||
## Methods
|
||||
### `init(value:total:)`
|
||||
|
||||
Initialize a progress bar widget.
|
||||
- Parameters:
|
||||
- value: The value.
|
||||
- total: The maximum value.
|
||||
|
||||
### `update(_:modifiers:)`
|
||||
|
||||
Update the view storage of the progress bar widget.
|
||||
- Parameters:
|
||||
- storage: The view storage.
|
||||
- modifiers: Modify views before being updated.
|
||||
|
||||
### `container(modifiers:)`
|
||||
|
||||
Get the container of the progress bar widget.
|
||||
- Returns: The view storage.
|
||||
@ -118,4 +118,11 @@ extension View {
|
||||
inspect { _ in onUpdate() }
|
||||
}
|
||||
|
||||
/// Make the view insensitive (useful e.g. in overlays).
|
||||
/// - Parameter insensitive: Whether the view is insensitive.
|
||||
/// - Returns: A view.
|
||||
public func insensitive(_ insensitive: Bool = true) -> View {
|
||||
inspect { _ = $0?.sensitive(!insensitive) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
46
Sources/Adwaita/View/ProgressBar.swift
Normal file
46
Sources/Adwaita/View/ProgressBar.swift
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Progressbar.swift
|
||||
// Adwaita
|
||||
//
|
||||
// Created by david-swift on 03.01.24.
|
||||
//
|
||||
|
||||
import Libadwaita
|
||||
|
||||
/// A progress bar widget.
|
||||
public struct ProgressBar: Widget {
|
||||
|
||||
/// The value.
|
||||
var value: Double
|
||||
|
||||
/// Initialize a progress bar widget.
|
||||
/// - Parameters:
|
||||
/// - value: The value.
|
||||
/// - total: The maximum value.
|
||||
public init(value: Double, total: Double) {
|
||||
if total != 0 {
|
||||
self.value = value / total
|
||||
} else {
|
||||
self.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the view storage of the progress bar widget.
|
||||
/// - Parameters:
|
||||
/// - storage: The view storage.
|
||||
/// - modifiers: Modify views before being updated.
|
||||
public func update(_ storage: ViewStorage, modifiers: [(View) -> View]) {
|
||||
if let bar = storage.view as? Libadwaita.ProgressBar {
|
||||
_ = bar.fraction(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the container of the progress bar widget.
|
||||
/// - Returns: The view storage.
|
||||
public func container(modifiers: [(View) -> View]) -> ViewStorage {
|
||||
let bar = Libadwaita.ProgressBar().fraction(value)
|
||||
_ = bar.sensitive(false)
|
||||
return .init(bar)
|
||||
}
|
||||
|
||||
}
|
||||
@ -20,6 +20,7 @@ This is an overview of the available widgets and other components in _Adwaita_.
|
||||
| Container | Supports any widget conforming to `Libadwaita.InsertableContainer`. | Multiple widgets |
|
||||
| Carousel | A paginated scrolling widget. | AdwCarousel |
|
||||
| ViewSwitcher | A control for switching between different views. | AdwViewSwitcher |
|
||||
| ProgressBar | A bar showing a progress. | GtkProgressBar |
|
||||
| StateWrapper | A wrapper not affecting the UI which stores state information. | - |
|
||||
|
||||
### View Modifiers
|
||||
@ -47,6 +48,7 @@ This is an overview of the available widgets and other components in _Adwaita_.
|
||||
| `toast(_:signal:)` | Show a toast on top of the view whenever the signal gets activated. |
|
||||
| `toast(_:signal:button:handler:)` | Show a toast with a button on top of the view whenever the signal gets activated. |
|
||||
| `overlay(_:)` | Overlay a view with another view. |
|
||||
| `insensitive(_:)` | Make a view unable to detect actions. This is especially useful for overlays. |
|
||||
|
||||
### `Button` Modifiers
|
||||
| Syntax | Description |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user