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

Commit

Permalink
Add modifier for centering a view horizontally
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 4, 2024
1 parent 5a625e3 commit 2ac37b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Adwaita/View/Modifiers/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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

0 comments on commit 2ac37b3

Please sign in to comment.