diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 307671d..b201e2b 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -22,4 +22,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: f0cdc6633e8d65e479af433fa427d7c0ce7c72b1 -COCOAPODS: 1.11.3 +COCOAPODS: 1.14.3 diff --git a/Paralayout/ViewDistributionAxis.swift b/Paralayout/ViewDistributionAxis.swift index af5a5bf..0885886 100644 --- a/Paralayout/ViewDistributionAxis.swift +++ b/Paralayout/ViewDistributionAxis.swift @@ -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: diff --git a/Paralayout/ViewDistributionItem.swift b/Paralayout/ViewDistributionItem.swift index dae79f8..77a98b9 100644 --- a/Paralayout/ViewDistributionItem.swift +++ b/Paralayout/ViewDistributionItem.swift @@ -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`. @@ -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 } }