Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Add support for GtkProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 3, 2024
1 parent 4f876fa commit bd2687b
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Documentation/Reference/extensions/View.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions Documentation/Reference/structs/ProgressBar.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions Sources/Adwaita/View/Modifiers/InspectorWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 46 additions & 0 deletions Sources/Adwaita/View/ProgressBar.swift
Original file line number Diff line number Diff line change
@@ -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)
}

}
2 changes: 2 additions & 0 deletions user-manual/Information/Widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit bd2687b

Please sign in to comment.