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

Use CGSize to define fixed spacers #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: f0cdc6633e8d65e479af433fa427d7c0ce7c72b1

COCOAPODS: 1.11.3
COCOAPODS: 1.14.3
9 changes: 0 additions & 9 deletions Paralayout/ViewDistributionAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ internal enum ViewDistributionAxis {

// MARK: - Internal Methods

internal func amount(of insets: UIEdgeInsets) -> CGFloat {
switch self {
case .horizontal:
return insets.horizontalAmount
case .vertical:
return insets.verticalAmount
}
}

internal func size(of rect: CGRect) -> CGFloat {
switch self {
case .horizontal:
Expand Down
26 changes: 19 additions & 7 deletions Paralayout/ViewDistributionItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public enum ViewDistributionItem: ViewDistributionSpecifying {
case view(UIView, UIEdgeInsets)

/// A constant spacer between two other elements.
case fixed(CGFloat)
case fixed(CGSize)

/// Proportional spacer, a fraction of the space not taken up by UIViews or fixed spacers.
case flexible(CGFloat)

// MARK: - Public Static Methods

public static func fixed(_ dimension: CGFloat) -> ViewDistributionItem {
.fixed(.init(width: dimension, height: dimension))
}

// MARK: - Public Properties

/// Itself: `DistributionItem` trivially conforms to `ViewDistributionSpecifying`.
Expand Down Expand Up @@ -129,14 +135,20 @@ public enum ViewDistributionItem: ViewDistributionSpecifying {
/// Returns the length of the DistributionItem (`axis` and `multiplier` are relevant only for `.view` and
/// `.flexible` items, respectively).
internal func layoutSize(along axis: ViewDistributionAxis, multiplier: CGFloat = 1) -> CGFloat {
switch self {
case .view(let view, let insets):
return axis.size(of: view.untransformedFrame) - axis.amount(of: insets)
switch (self, axis) {
case let (.view(view, insets), .horizontal):
return axis.size(of: view.untransformedFrame) - insets.horizontalAmount

case let (.view(view, insets), .vertical):
return axis.size(of: view.untransformedFrame) - insets.verticalAmount

case let (.fixed(size), .horizontal):
return size.width

case .fixed(let margin):
return margin
case let (.fixed(size), .vertical):
return size.height

case .flexible(let space):
case let (.flexible(space), _):
return space * multiplier
}
}
Expand Down
Loading