Skip to content

Commit

Permalink
Add shorthand operator >> for constraining size
Browse files Browse the repository at this point in the history
  • Loading branch information
flowtoolz committed Jan 3, 2020
1 parent 90da1a2 commit 039fdce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Code/AllPlatforms/Core API/Dimensions/Dimension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AppKit
import UIKit
#endif

// MARK: - Constrain Layout Item
// MARK: - Constrain LayoutItem

@discardableResult
public func >>(item: LayoutItem, size: CGFloat) -> [NSLayoutConstraint]
Expand Down Expand Up @@ -190,6 +190,8 @@ public extension DimensionAnchor
}
}

// MARK: - Types

public struct DimensionTarget: Target
{
public static func max(_ constant: CGFloat) -> Self
Expand Down
12 changes: 12 additions & 0 deletions Code/AllPlatforms/Core API/Dimensions/SizeTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import UIKit

// TODO: provide shorthand operator for constrain(to: functions. (the "core API")

@discardableResult
public func >>(item: LayoutItem, size: (CGFloat, CGFloat)) -> [NSLayoutConstraint]
{
item.constrain(to: size.0, size.1)
}

@discardableResult
public func >>(item: LayoutItem, target: SizeTarget?) -> [NSLayoutConstraint]
{
item.constrain(to: target)
}

public extension LayoutItem
{
@discardableResult
Expand Down

0 comments on commit 039fdce

Please sign in to comment.