Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable trailing closures for distribution builder with parameters #121

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions Paralayout/UIView+Distribution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extension UIView {
/// **Examples:**
///
/// To stack two elements with a 10 pt margin between them:
/// ```
/// ```swift
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooooooooooh good stuff

/// // This is effectively the same as [ 1.flexible, icon, 10.fixed, label, 1.flexible ].
/// applyVerticalSubviewDistribution {
/// icon
Expand All @@ -171,7 +171,7 @@ extension UIView {
/// ```
///
/// To evenly spread out items:
/// ```
/// ```swift
/// // This is effectively the same as [ 1.flexible, button1, 1.flexible, button2, 1.flexible, button3 ].
/// applyVerticalSubviewDistribution {
/// button1
Expand All @@ -181,7 +181,7 @@ extension UIView {
/// ```
///
/// To stack two elements with 50% more space below than above:
/// ```
/// ```swift
/// applyVerticalSubviewDistribution {
/// 2.flexible
/// label
Expand All @@ -192,7 +192,7 @@ extension UIView {
/// ```
///
/// To arrange a pair of label on the top and bottom edges of a view, with another label centered between them:
/// ```
/// ```swift
/// applyVerticalSubviewDistribution {
/// 8.fixed
/// headerLabel
Expand All @@ -205,45 +205,45 @@ extension UIView {
/// ```
///
/// To arrange UI in a view with an interior margin:
/// ```
/// applyVerticalSubviewDistribution {
/// ```swift
/// applyVerticalSubviewDistribution(inRect: bounds.insetBy(dx: 20, dy: 40)) {
/// icon
/// 10.fixed
/// label
/// }, inRect: bounds.insetBy(dx: 20, dy: 40))
/// }
/// ```
///
/// To arrange UI vertically aligned by their leading edge 10 pt in from the leading edge of their superview:
/// ```
/// applyVerticalSubviewDistribution {
/// ```swift
/// applyVerticalSubviewDistribution(orthogonalOffset: .leading(inset: 10)) {
/// icon
/// 1.flexible
/// button
/// }, orthogonalOffset: .leading(inset: 10))
/// }
/// ```
///
/// To arrange UI vertically without simultaneously centering it horizontally (the `icon` would need independent
/// horizontal positioning):
/// ```
/// applyVerticalSubviewDistribution {
/// ```swift
/// applyVerticalSubviewDistribution(orthogonalOffset: nil) {
/// 1.flexible
/// icon
/// 2.flexible
/// }, orthogonalOffset: nil)
/// }
/// ```
///
/// - precondition: All views in the `distribution` must be subviews of the receiver.
/// - precondition: The `distribution` must not include any given view more than once.
///
/// - parameter distribution: An array of distribution specifiers, ordered from the top edge to the bottom edge.
/// - parameter layoutBounds: The region in the receiver in which to distribute the view in the receiver's
/// coordinate space. Specify `nil` to use the receiver's bounds. Defaults to `nil`.
/// - parameter orthogonalAlignment: The horizontal alignment to apply to the views. If `nil`, views are left in
/// their horizontal position prior to the distribution. Defaults to centered with no offset.
/// - parameter distribution: An array of distribution specifiers, ordered from the top edge to the bottom edge.
public func applyVerticalSubviewDistribution(
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying],
inRect layoutBounds: CGRect? = nil,
orthogonalAlignment: HorizontalDistributionAlignment? = .centered(offset: 0)
orthogonalAlignment: HorizontalDistributionAlignment? = .centered(offset: 0),
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying]
) {
applyVerticalSubviewDistribution(
distribution(),
Expand Down Expand Up @@ -343,7 +343,7 @@ extension UIView {
/// **Examples:**
///
/// To stack two elements with a 10 pt margin between them:
/// ```
/// ```swift
/// // This is effectively the same as [ 1.flexible, icon, 10.fixed, label, 1.flexible ].
/// applyHorizontalSubviewDistribution {
/// icon
Expand All @@ -353,7 +353,7 @@ extension UIView {
/// ```
///
/// To evenly spread out items:
/// ```
/// ```swift
/// // This is effectively the same as [ 1.flexible, button1, 1.flexible, button2, 1.flexible, button3 ].
/// applyHorizontalSubviewDistribution {
/// button1
Expand All @@ -363,7 +363,7 @@ extension UIView {
/// ```
///
/// To stack two elements with 50% more space after than before:
/// ```
/// ```swift
/// applyHorizontalSubviewDistribution {
/// 2.flexible
/// label
Expand All @@ -374,7 +374,7 @@ extension UIView {
/// ```
///
/// To arrange a pair of buttons on the left and right edges of a view, with a label centered between them:
/// ```
/// ```swift
/// applyHorizontalSubviewDistribution {
/// 8.fixed
/// backButton
Expand All @@ -387,46 +387,46 @@ extension UIView {
/// ```
///
/// To arrange UI in a view with an interior margin:
/// ```
/// applyHorizontalSubviewDistribution {
/// ```swift
/// applyHorizontalSubviewDistribution(inRect: bounds.insetBy(dx: 20, dy: 40)) {
/// icon
/// 10.fixed
/// label
/// }, inRect: bounds.insetBy(dx: 20, dy: 40))
/// }
/// ```
///
/// To arrange UI horizontally aligned by their top edge 10 pt in from the top edge of their superview:
/// ```
/// applyHorizontalSubviewDistribution {
/// ```swift
/// applyHorizontalSubviewDistribution(orthogonalOffset: .top(inset: 10)) {
/// icon
/// 1.flexible
/// button
/// }, orthogonalOffset: .top(inset: 10))
/// }
/// ```
///
/// To arrange UI horizontally without simultaneously centering it vertically (the `icon` would need independent
/// vertical positioning):
/// ```
/// applyHorizontalSubviewDistribution {
/// ```swift
/// applyHorizontalSubviewDistribution(orthogonalOffset: nil) {
/// 1.flexible
/// icon
/// 2.flexible
/// }, orthogonalOffset: nil)
/// }
/// ```
///
/// - precondition: All views in the `distribution` must be subviews of the receiver.
/// - precondition: The `distribution` must not include any given view more than once.
///
/// - parameter distribution: An array of distribution specifiers, ordered from the leading edge to the trailing
/// edge.
/// - parameter layoutBounds: The region in the receiver in which to distribute the view in the receiver's
/// coordinate space. Specify `nil` to use the receiver's bounds. Defaults to `nil`.
/// - parameter orthogonalAlignment: The vertical alignment to apply to the views. If `nil`, views are left in
/// their vertical position prior to the distribution. Defaults to centered with no offset.
/// - parameter distribution: An array of distribution specifiers, ordered from the leading edge to the trailing
/// edge.
public func applyHorizontalSubviewDistribution(
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying],
inRect layoutBounds: CGRect? = nil,
orthogonalAlignment: VerticalDistributionAlignment? = .centered(offset: 0)
orthogonalAlignment: VerticalDistributionAlignment? = .centered(offset: 0),
@ViewDistributionBuilder _ distribution: () -> [ViewDistributionSpecifying]
) {
applyHorizontalSubviewDistribution(
distribution(),
Expand Down