Add modifier for centering a view horizontally

This commit is contained in:
david-swift 2024-01-04 16:42:05 +01:00
parent 5a625e31a7
commit 2ac37b3f9c
2 changed files with 8 additions and 0 deletions

View File

@ -14,4 +14,11 @@ extension View {
.valign(.center)
}
/// Wrap the view in a horizontal stack and center horizontally.
/// - Returns: The view.
public func horizontalCenter() -> View {
HStack { self }
.halign(.center)
}
}

View File

@ -59,6 +59,7 @@ This is an overview of the available widgets and other components in _Adwaita_.
| `insensitive(_:)` | Make a view unable to detect actions. This is especially useful for overlays. |
| `onClick(handler:)` | Run a function when the user clicks on the widget. |
| `verticalCenter()` | Wrap a view in a `VStack` and center vertically. |
| `horizontalCenter()` | Wrap a view in an `HStack` and center horizontally. |
### `Button` Modifiers
| Syntax | Description |