diff --git a/Documentation/Reference/README.md b/Documentation/Reference/README.md index 514d294..a6e55af 100644 --- a/Documentation/Reference/README.md +++ b/Documentation/Reference/README.md @@ -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) diff --git a/Documentation/Reference/extensions/View.md b/Documentation/Reference/extensions/View.md index ea986f4..ed6466d 100644 --- a/Documentation/Reference/extensions/View.md +++ b/Documentation/Reference/extensions/View.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. diff --git a/Documentation/Reference/structs/ProgressBar.md b/Documentation/Reference/structs/ProgressBar.md new file mode 100644 index 0000000..442c20e --- /dev/null +++ b/Documentation/Reference/structs/ProgressBar.md @@ -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. diff --git a/Sources/Adwaita/View/Modifiers/InspectorWrapper.swift b/Sources/Adwaita/View/Modifiers/InspectorWrapper.swift index b4b84e3..26b037c 100644 --- a/Sources/Adwaita/View/Modifiers/InspectorWrapper.swift +++ b/Sources/Adwaita/View/Modifiers/InspectorWrapper.swift @@ -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) } + } + } diff --git a/Sources/Adwaita/View/ProgressBar.swift b/Sources/Adwaita/View/ProgressBar.swift new file mode 100644 index 0000000..4367c3e --- /dev/null +++ b/Sources/Adwaita/View/ProgressBar.swift @@ -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) + } + +} diff --git a/user-manual/Information/Widgets.md b/user-manual/Information/Widgets.md index be55d5c..283ea0d 100644 --- a/user-manual/Information/Widgets.md +++ b/user-manual/Information/Widgets.md @@ -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 |