From 2ac37b3f9c86fd49361883f2db74258a9dd19425 Mon Sep 17 00:00:00 2001 From: david-swift Date: Thu, 4 Jan 2024 16:42:05 +0100 Subject: [PATCH] Add modifier for centering a view horizontally --- Sources/Adwaita/View/Modifiers/View+.swift | 7 +++++++ user-manual/Information/Widgets.md | 1 + 2 files changed, 8 insertions(+) diff --git a/Sources/Adwaita/View/Modifiers/View+.swift b/Sources/Adwaita/View/Modifiers/View+.swift index 91b3023..e2ebd3e 100644 --- a/Sources/Adwaita/View/Modifiers/View+.swift +++ b/Sources/Adwaita/View/Modifiers/View+.swift @@ -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) + } + } diff --git a/user-manual/Information/Widgets.md b/user-manual/Information/Widgets.md index f55a8fa..e2260b4 100644 --- a/user-manual/Information/Widgets.md +++ b/user-manual/Information/Widgets.md @@ -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 |