diff --git a/Example/PinLayoutSample/UI/Examples/IntroObjectiveC/IntroObjectiveCView.m b/Example/PinLayoutSample/UI/Examples/IntroObjectiveC/IntroObjectiveCView.m index d66db422..cf19e91a 100644 --- a/Example/PinLayoutSample/UI/Examples/IntroObjectiveC/IntroObjectiveCView.m +++ b/Example/PinLayoutSample/UI/Examples/IntroObjectiveC/IntroObjectiveCView.m @@ -67,11 +67,11 @@ - (void) layoutSubviews { CGFloat margin = 10; UIEdgeInsets safeArea = self.pinObjc.safeArea; - - [[[[[[logo.pinObjc topWithInsets:safeArea] leftWithInsets:safeArea] width:100] aspectRatio] margin:margin] layout]; - [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] rightWithInsets:safeArea] marginHorizontal:margin] layout]; - [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:margin] sizeToFit:FitWidth] layout]; - [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:margin] layout]; + + logo.pinObjc.topInsets(safeArea).leftInsets(safeArea).width(100).aspectRatio().margin(margin).layout(); + segmented.pinObjc.rightOfAligned(logo, VerticalAlignTop).rightInsets(safeArea).marginHorizontal(margin).layout(); + textLabel.pinObjc.belowOfAligned(segmented, HorizontalAlignLeft).widthOf(segmented).pinEdges().marginTop(margin).sizeToFitType(FitWidth).layout(); + separatorView.pinObjc.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft).rightToEdge(segmented.edge.right).height(1).marginTop(margin).layout(); } - (void) setLayoutGuidesTop:(CGFloat)top { diff --git a/Sources/ObjectiveC/PinLayoutObjC.swift b/Sources/ObjectiveC/PinLayoutObjC.swift index e40bccb5..1e21646a 100644 --- a/Sources/ObjectiveC/PinLayoutObjC.swift +++ b/Sources/ObjectiveC/PinLayoutObjC.swift @@ -33,233 +33,216 @@ import AppKit #if os(iOS) || os(tvOS) var safeArea: PEdgeInsets { get } #endif + + typealias POVoid = () -> PinLayoutObjC? + typealias POValue = (_ value: CGFloat) -> PinLayoutObjC? + typealias POEdgeInsets = (_ insets: PEdgeInsets) -> PinLayoutObjC? + typealias POVEdge = (_ edge: VerticalEdge) -> PinLayoutObjC? + typealias POHEdge = (_ edge: HorizontalEdge) -> PinLayoutObjC? + typealias POAnchor = (_ anchor: Anchor) -> PinLayoutObjC? + typealias POSize = (_ size: CGSize) -> PinLayoutObjC? + typealias POHAlign = (_ hAlign: HorizontalAlign) -> PinLayoutObjC? + typealias POVAlign = (_ hAlign: VerticalAlign) -> PinLayoutObjC? + typealias POWrapType = (_ type: WrapType) -> PinLayoutObjC? + typealias POWrapTypePadding = (_ type: WrapType, _ padding: CGFloat) -> PinLayoutObjC? + typealias POWrapTypeInsets = (_ type: WrapType, _ insets: PEdgeInsets) -> PinLayoutObjC? + typealias POFitType = (_ type: Fit) -> PinLayoutObjC? /** With the Objective-C interface, you must call the \"layout\" method to ensure the view is layouted correctly. Ex: - [[[textLabel.pin_objc top] left] layout];" - [[[textLabel.pin_objc top] left] layout];" + textLabel.pinObjc.top().left().layout() */ - func layout() + var layout: POVoid { get } + + var top: POVoid { get } + var topValue: POValue { get } + var topPercent: POValue { get } + var topInsets: POEdgeInsets { get } + + var left: POVoid { get } + var leftValue: POValue { get } + var leftPercent: POValue { get } + var leftInsets: POEdgeInsets { get } + + var bottom: POVoid { get } + var bottomValue: POValue { get } + var bottomPercent: POValue { get } + var bottomInsets: POEdgeInsets { get } + + var right: POVoid { get } + var rightValue: POValue { get } + var rightPercent: POValue { get } + var rightInsets: POEdgeInsets { get } + + var hCenter: POVoid { get } + var hCenterValue: POValue { get } + var hCenterPercent: POValue { get } + + var vCenter: POVoid { get } + var vCenterValue: POValue { get } + var vCenterPercent: POValue { get } - @discardableResult func top() -> PinLayoutObjC - @discardableResult func top(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func top(percent: CGFloat) -> PinLayoutObjC - @discardableResult func top(insets: PEdgeInsets) -> PinLayoutObjC - - @discardableResult func left() -> PinLayoutObjC - @discardableResult func left(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func left(percent: CGFloat) -> PinLayoutObjC - @discardableResult func left(insets: PEdgeInsets) -> PinLayoutObjC - - @discardableResult func bottom() -> PinLayoutObjC - @discardableResult func bottom(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func bottom(percent: CGFloat) -> PinLayoutObjC - @discardableResult func bottom(insets: PEdgeInsets) -> PinLayoutObjC - - @discardableResult func right() -> PinLayoutObjC - @discardableResult func right(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func right(percent: CGFloat) -> PinLayoutObjC - @discardableResult func right(insets: PEdgeInsets) -> PinLayoutObjC - - @discardableResult func hCenter() -> PinLayoutObjC - @discardableResult func hCenter(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func hCenter(percent: CGFloat) -> PinLayoutObjC - - @discardableResult func vCenter() -> PinLayoutObjC - @discardableResult func vCenter(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func vCenter(percent: CGFloat) -> PinLayoutObjC - // RTL support - @discardableResult func start() -> PinLayoutObjC - @discardableResult func start(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func start(percent: CGFloat) -> PinLayoutObjC - @discardableResult func start(insets: PEdgeInsets) -> PinLayoutObjC - - @discardableResult func end() -> PinLayoutObjC - @discardableResult func end(_ value: CGFloat) -> PinLayoutObjC - @discardableResult func end(percent: CGFloat) -> PinLayoutObjC - @discardableResult func end(insets: PEdgeInsets) -> PinLayoutObjC - + var start: POVoid { get } + var startValue: POValue { get } + var startPercent: POValue { get } + var startInsets: POEdgeInsets { get } + + var end: POVoid { get } + var endValue: POValue { get } + var endPercent: POValue { get } + var endInsets: POEdgeInsets { get } + // Pin multiple edges at once. - @discardableResult func all() -> PinLayoutObjC - @discardableResult func horizontally() -> PinLayoutObjC - @discardableResult func vertically() -> PinLayoutObjC - + var all: POVoid { get } + var horizontally: POVoid { get } + var vertically: POVoid { get } + // // MARK: Layout using edges // - @discardableResult func top(to edge: VerticalEdge) -> PinLayoutObjC - @discardableResult func vCenter(to edge: VerticalEdge) -> PinLayoutObjC - @discardableResult func bottom(to edge: VerticalEdge) -> PinLayoutObjC - @discardableResult func left(to edge: HorizontalEdge) -> PinLayoutObjC - @discardableResult func hCenter(to edge: HorizontalEdge) -> PinLayoutObjC - @discardableResult func right(to edge: HorizontalEdge) -> PinLayoutObjC + var topToEdge: POVEdge { get } + var vCenterToEdge: POVEdge { get } + var bottomToEdge: POVEdge { get } + var leftToEdge: POHEdge { get } + var hCenterToEdge: POHEdge { get } + var rightToEdge: POHEdge { get } + // RTL support - @discardableResult func start(to edge: HorizontalEdge) -> PinLayoutObjC - @discardableResult func end(to edge: HorizontalEdge) -> PinLayoutObjC - + var startToEdge: POHEdge { get } + var endToEdge: POHEdge { get } + // // MARK: Layout using anchors // - @discardableResult func topLeft(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func topLeft() -> PinLayoutObjC - @discardableResult func topStart(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func topStart() -> PinLayoutObjC - - @discardableResult func topCenter(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func topCenter() -> PinLayoutObjC - - @discardableResult func topRight(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func topRight() -> PinLayoutObjC - @discardableResult func topEnd(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func topEnd() -> PinLayoutObjC - - @discardableResult func centerLeft(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func centerLeft() -> PinLayoutObjC - @discardableResult func centerStart(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func centerStart() -> PinLayoutObjC - - @discardableResult func center(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func center() -> PinLayoutObjC - - @discardableResult func centerRight(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func centerRight() -> PinLayoutObjC - @discardableResult func centerEnd(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func centerEnd() -> PinLayoutObjC - - @discardableResult func bottomLeft(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func bottomLeft() -> PinLayoutObjC - @discardableResult func bottomStart(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func bottomStart() -> PinLayoutObjC - - @discardableResult func bottomCenter(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func bottomCenter() -> PinLayoutObjC - - @discardableResult func bottomRight(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func bottomRight() -> PinLayoutObjC - @discardableResult func bottomEnd(to anchor: Anchor) -> PinLayoutObjC - @discardableResult func bottomEnd() -> PinLayoutObjC - + var topLeftToAnchor: POAnchor { get } + var topLeft: POVoid { get } + var topStartToAnchor: POAnchor { get } + var topStart: POVoid { get } + + var topCenterToAnchor: POAnchor { get } + var topCenter: POVoid { get } + + var topRightToAnchor: POAnchor { get } + var topRight: POVoid { get } + var topEndToAnchor: POAnchor { get } + var topEnd: POVoid { get } + + var centerLeftToAnchor: POAnchor { get } + var centerLeft: POVoid { get } + var centerStartToAnchor: POAnchor { get } + var centerStart: POVoid { get } + + var centerToAnchor: POAnchor { get } + var center: POVoid { get } + + var centerRightToAnchor: POAnchor { get } + var centerRight: POVoid { get } + var centerEndToAnchor: POAnchor { get } + var centerEnd: POVoid { get } + + var bottomLeftToAnchor: POAnchor { get } + var bottomLeft: POVoid { get } + var bottomStartToAnchor: POAnchor { get } + var bottomStart: POVoid { get } + + var bottomCenterToAnchor: POAnchor { get } + var bottomCenter: POVoid { get } + + var bottomRightToAnchor: POAnchor { get } + var bottomRight: POVoid { get } + var bottomEndToAnchor: POAnchor { get } + var bottomEnd: POVoid { get } + // // MARK: Layout using relative positioning // #if os(iOS) || os(tvOS) - @discardableResult func above(of: UIView) -> PinLayoutObjC - @discardableResult func above(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func above(of: UIView, aligned: HorizontalAlign) -> PinLayoutObjC - @discardableResult func above(ofViews: [UIView], aligned: HorizontalAlign) -> PinLayoutObjC - - @discardableResult func below(of: UIView) -> PinLayoutObjC - @discardableResult func below(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func below(of: UIView, aligned: HorizontalAlign) -> PinLayoutObjC - @discardableResult func below(ofViews: [UIView], aligned: HorizontalAlign) -> PinLayoutObjC - - @discardableResult func left(of: UIView) -> PinLayoutObjC - @discardableResult func left(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func left(of: UIView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func left(ofViews: [UIView], aligned: VerticalAlign) -> PinLayoutObjC - - @discardableResult func right(of: UIView) -> PinLayoutObjC - @discardableResult func right(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func right(of: UIView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func right(ofViews: [UIView], aligned: VerticalAlign) -> PinLayoutObjC - - // RTL support - @discardableResult func before(of: UIView) -> PinLayoutObjC - @discardableResult func before(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func before(of: UIView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func before(ofViews: [UIView], aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func after(of: UIView) -> PinLayoutObjC - @discardableResult func after(ofViews: [UIView]) -> PinLayoutObjC - @discardableResult func after(of: UIView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func after(ofViews: [UIView], aligned: VerticalAlign) -> PinLayoutObjC + typealias POView = (_ view: UIView) -> PinLayoutObjC? + typealias POViews = (_ views: [UIView]) -> PinLayoutObjC? + typealias POViewHAligned = (_ view: UIView, _ aligned: HorizontalAlign) -> PinLayoutObjC? + typealias POViewsHAligned = (_ views: [UIView], _ aligned: HorizontalAlign) -> PinLayoutObjC? + typealias POViewVAligned = (_ view: UIView, _ aligned: VerticalAlign) -> PinLayoutObjC? + typealias POViewsVAligned = (_ views: [UIView], _ aligned: VerticalAlign) -> PinLayoutObjC? #elseif os(macOS) - @discardableResult func above(of: NSView) -> PinLayoutObjC - @discardableResult func above(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func above(of: NSView, aligned: HorizontalAlign) -> PinLayoutObjC - @discardableResult func above(ofViews: [NSView], aligned: HorizontalAlign) -> PinLayoutObjC - - @discardableResult func below(of: NSView) -> PinLayoutObjC - @discardableResult func below(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func below(of: NSView, aligned: HorizontalAlign) -> PinLayoutObjC - @discardableResult func below(ofViews: [NSView], aligned: HorizontalAlign) -> PinLayoutObjC - - @discardableResult func left(of: NSView) -> PinLayoutObjC - @discardableResult func left(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func left(of: NSView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func left(ofViews: [NSView], aligned: VerticalAlign) -> PinLayoutObjC - - @discardableResult func right(of: NSView) -> PinLayoutObjC - @discardableResult func right(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func right(of: NSView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func right(ofViews: [NSView], aligned: VerticalAlign) -> PinLayoutObjC - - // RTL support - @discardableResult func before(of: NSView) -> PinLayoutObjC - @discardableResult func before(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func before(of: NSView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func before(ofViews: [NSView], aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func after(of: NSView) -> PinLayoutObjC - @discardableResult func after(ofViews: [NSView]) -> PinLayoutObjC - @discardableResult func after(of: NSView, aligned: VerticalAlign) -> PinLayoutObjC - @discardableResult func after(ofViews: [NSView], aligned: VerticalAlign) -> PinLayoutObjC + typealias POView = (_ view: NSView) -> PinLayoutObjC? + typealias POViews = (_ views: [NSView]) -> PinLayoutObjC? + typealias POViewHAligned = (_ view: NSView, _ aligned: HorizontalAlign) -> PinLayoutObjC? + typealias POViewsHAligned = (_ views: [NSView], _ aligned: HorizontalAlign) -> PinLayoutObjC? + typealias POViewVAligned = (_ view: NSView, _ aligned: VerticalAlign) -> PinLayoutObjC? + typealias POViewsVAligned = (_ views: [NSView], _ aligned: VerticalAlign) -> PinLayoutObjC? #endif + + var aboveOf: POView { get } + var aboveOfViews: POViews { get } + var aboveOfAligned: POViewHAligned { get } + var aboveOfViewsAligned: POViewsHAligned { get } + + var belowOf: POView { get } + var belowOfViews: POViews { get } + var belowOfAligned: POViewHAligned { get } + var belowOfViewsAligned: POViewsHAligned { get } + var leftOf: POView { get } + var leftOfViews: POViews { get } + var leftOfAligned: POViewVAligned { get } + var leftOfViewsAligned: POViewsVAligned { get } + + var rightOf: POView { get } + var rightOfViews: POViews { get } + var rightOfAligned: POViewVAligned { get } + var rightOfViewsAligned: POViewsVAligned { get } + + // RTL support + var beforeOf: POView { get } + var beforeOfViews: POViews { get } + var beforeOfAligned: POViewVAligned { get } + var beforeOfViewsAligned: POViewsVAligned { get } + var afterOf: POView { get } + var afterOfViews: POViews { get } + var afterOfAligned: POViewVAligned { get } + var afterOfViewsAligned: POViewsVAligned { get } // // MARK: justify / align // - @discardableResult func justify(_: HorizontalAlign) -> PinLayoutObjC - @discardableResult func align(_: VerticalAlign) -> PinLayoutObjC + var justify: POHAlign { get } + var align: POVAlign { get } // // MARK: Width, height and size // - @discardableResult func width(_ width: CGFloat) -> PinLayoutObjC - @discardableResult func width(percent: CGFloat) -> PinLayoutObjC - #if os(iOS) || os(tvOS) - @discardableResult func width(of view: UIView) -> PinLayoutObjC - #elseif os(macOS) - @discardableResult func width(of view: NSView) -> PinLayoutObjC - #endif + var width: POValue { get } + var widthPercent: POValue { get } + var widthOf: POView { get } - @discardableResult func minWidth(_ width: CGFloat) -> PinLayoutObjC - @discardableResult func minWidth(percent: CGFloat) -> PinLayoutObjC - @discardableResult func maxWidth(_ width: CGFloat) -> PinLayoutObjC - @discardableResult func maxWidth(percent: CGFloat) -> PinLayoutObjC + var minWidth: POValue { get } + var minWidthPercent: POValue { get } + var maxWidth: POValue { get } + var maxWidthPercent: POValue { get } - @discardableResult func height(_ height: CGFloat) -> PinLayoutObjC - @discardableResult func height(percent: CGFloat) -> PinLayoutObjC - #if os(iOS) || os(tvOS) - @discardableResult func height(of view: UIView) -> PinLayoutObjC - #elseif os(macOS) - @discardableResult func height(of view: NSView) -> PinLayoutObjC - #endif + var height: POValue { get } + var heightPercent: POValue { get } + var heightOf: POView { get } - @discardableResult func minHeight(_ height: CGFloat) -> PinLayoutObjC - @discardableResult func minHeight(percent: CGFloat) -> PinLayoutObjC - @discardableResult func maxHeight(_ height: CGFloat) -> PinLayoutObjC - @discardableResult func maxHeight(percent: CGFloat) -> PinLayoutObjC + var minHeight: POValue { get } + var minHeightPercent: POValue { get } + var maxHeight: POValue { get } + var maxHeightPercent: POValue { get } + + var size: POSize { get } + var sizeLength: POValue { get } + var sizePercent: POValue { get } + var sizeOf: POView{ get } - @discardableResult func size(_ size: CGSize) -> PinLayoutObjC - @discardableResult func size(length: CGFloat) -> PinLayoutObjC - @discardableResult func size(percent: CGFloat) -> PinLayoutObjC - #if os(iOS) || os(tvOS) - @discardableResult func size(of view: UIView) -> PinLayoutObjC - #elseif os(macOS) - @discardableResult func size(of view: NSView) -> PinLayoutObjC - #endif - - // // MARK: wrapContent - @discardableResult func wrapContent() -> PinLayoutObjC; - @discardableResult func wrapContent(padding: CGFloat) -> PinLayoutObjC; - @discardableResult func wrapContent(insets: PEdgeInsets) -> PinLayoutObjC; - @discardableResult func wrapContent(type: WrapType) -> PinLayoutObjC; - @discardableResult func wrapContent(type: WrapType, padding: CGFloat) -> PinLayoutObjC; - @discardableResult func wrapContent(type: WrapType, insets: PEdgeInsets) -> PinLayoutObjC; - + var wrapContent: POVoid { get } + var wrapContentPadding: POValue { get } + var wrapContentInsets: POEdgeInsets { get } + var wrapContentType: POWrapType { get } + var wrapContentTypePadding: POWrapTypePadding { get } + var wrapContentTypeInsets: POWrapTypeInsets { get } /** Set the view aspect ratio. @@ -272,7 +255,7 @@ import AppKit * AspectRatio respects the min (minWidth/minHeight) and the max (maxWidth/maxHeight) dimensions of an item. */ - @discardableResult func aspectRatio(_ ratio: CGFloat) -> PinLayoutObjC + var aspectRatioValue: POValue { get } /** Set the view aspect ratio using another UIView's aspect ratio. @@ -283,11 +266,7 @@ import AppKit * AspectRatio respects the min (minWidth/minHeight) and the max (maxWidth/maxHeight) dimensions of an item. */ - #if os(iOS) || os(tvOS) - @discardableResult func aspectRatio(of view: UIView) -> PinLayoutObjC - #elseif os(macOS) - @discardableResult func aspectRatio(of view: NSView) -> PinLayoutObjC - #endif + var aspectRatioOf: POView { get } /** If the layouted view is an UIImageView, this method will set the aspectRatio using @@ -296,12 +275,12 @@ import AppKit For other types of views, this method as no impact. */ #if os(iOS) || os(tvOS) - @discardableResult func aspectRatio() -> PinLayoutObjC + var aspectRatio: POVoid { get } #endif - @discardableResult func sizeToFit() -> PinLayoutObjC - - @discardableResult func sizeToFit(_ fitType: Fit) -> PinLayoutObjC + var sizeToFit: POVoid { get } + + var sizeToFitType: POFitType { get } // // MARK: Margins @@ -310,22 +289,22 @@ import AppKit /** Set the top margin. */ - @discardableResult func marginTop(_ value: CGFloat) -> PinLayoutObjC + var marginTop: POValue { get } /** Set the left margin. */ - @discardableResult func marginLeft(_ value: CGFloat) -> PinLayoutObjC + var marginLeft: POValue { get } /** Set the bottom margin. */ - @discardableResult func marginBottom(_ value: CGFloat) -> PinLayoutObjC + var marginBottom: POValue { get } /** Set the right margin. */ - @discardableResult func marginRight(_ value: CGFloat) -> PinLayoutObjC + var marginRight: POValue { get } // RTL support /** @@ -335,7 +314,7 @@ import AppKit * In LTR direction, start margin specify the **left** margin. * In RTL direction, start margin specify the **right** margin. */ - @discardableResult func marginStart(_ value: CGFloat) -> PinLayoutObjC + var marginStart: POValue { get } /** Set the end margin. @@ -344,27 +323,23 @@ import AppKit * In LTR direction, end margin specify the **right** margin. * In RTL direction, end margin specify the **left** margin. */ - @discardableResult func marginEnd(_ value: CGFloat) -> PinLayoutObjC + var marginEnd: POValue { get } /** Set the left, right, start and end margins to the specified value. */ - @discardableResult func marginHorizontal(_ value: CGFloat) -> PinLayoutObjC + var marginHorizontal: POValue { get } /** Set the top and bottom margins to the specified value. */ - @discardableResult func marginVertical(_ value: CGFloat) -> PinLayoutObjC + var marginVertical: POValue { get } /** Set all margins using UIEdgeInsets. This method is particularly useful to set all margins using iOS 11 `UIView.safeAreaInsets`. */ - #if os(iOS) || os(tvOS) - @discardableResult func margin(insets: UIEdgeInsets) -> PinLayoutObjC - #elseif os(macOS) - @discardableResult func margin(insets: NSEdgeInsets) -> PinLayoutObjC - #endif + var marginInsets: POEdgeInsets { get } /** Set margins using NSDirectionalEdgeInsets. @@ -372,28 +347,28 @@ import AppKit Available only on iOS 11 and higher. */ - //@available(iOS 11.0, *) - //@discardableResult func margin(_ directionalInsets: NSDirectionalEdgeInsets) -> PinLayoutObjC + // @available(iOS 11.0, *) + // @discardableResult func margin(_ directionalInsets: NSDirectionalEdgeInsets) -> PinLayoutObjC /** Set all margins to the specified value. */ - @discardableResult func margin(_ value: CGFloat) -> PinLayoutObjC + var margin: POValue { get } /** Set individually vertical margins (top, bottom) and horizontal margins (left, right, start, end). */ - @discardableResult func margin(vertical: CGFloat, horizontal: CGFloat) -> PinLayoutObjC + var marginVH: (_ vertical: CGFloat, _ horizontal: CGFloat) -> PinLayoutObjC? { get } /** Set individually top, horizontal margins and bottom margin. */ - @discardableResult func margin(top: CGFloat, horizontal: CGFloat, bottom: CGFloat) -> PinLayoutObjC + var marginTHB: (_ top: CGFloat, _ horizontal: CGFloat, _ bottom: CGFloat) -> PinLayoutObjC? { get } /** Set individually top, left, bottom and right margins. */ - @discardableResult func margin(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> PinLayoutObjC + var marginTLBR: (_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat) -> PinLayoutObjC? { get } /// Normally if only either left or right has been specified, PinLayout will MOVE the view to apply left or right margins. /// This is also true even if the width has been set. @@ -401,9 +376,9 @@ import AppKit /// moving the view. /// /// - Returns: PinLayout - @discardableResult func pinEdges() -> PinLayoutObjC + var pinEdges: POVoid { get } } - + @objc public enum Fit: Int { case width case height diff --git a/Sources/ObjectiveC/PinLayoutObjCImpl.swift b/Sources/ObjectiveC/PinLayoutObjCImpl.swift index 3c2fb67c..0b98f912 100644 --- a/Sources/ObjectiveC/PinLayoutObjCImpl.swift +++ b/Sources/ObjectiveC/PinLayoutObjCImpl.swift @@ -70,729 +70,1001 @@ import AppKit } } - func layout() { - // With objective-c PinLayoutObjCImpl instance are sometimes deallocated only after the context has been quit. For this reason - // developpers must call the layout: method implicetely. - impl?.layout() - impl = nil - } - - func top() -> PinLayoutObjC { - _ = impl?.top() - return self + var layout: POVoid { + return { [weak self] in + _ = self?.impl?.layout() + self?.impl = nil + return self + } } - func top(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.top(value) - return self + var top: POVoid { + return { [weak self] in + _ = self?.impl?.top() + return self + } } - func top(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.top(percent%) - return self - } - - func top(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.top(insets) - return self + var topValue: POValue { + return { [weak self] value in + _ = self?.impl?.top(value) + return self + } } - func left() -> PinLayoutObjC { - _ = impl?.left() - return self + var topPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.top(percent%) + return self + } } - func left(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.left(value) - return self + var topInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.top(insets) + return self + } } - func left(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.left(percent%) - return self + var left: POVoid { + return { [weak self] in + _ = self?.impl?.left() + return self + } } - - func left(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.left(insets) - return self + + var leftValue: POValue { + return { [weak self] value in + _ = self?.impl?.left(value) + return self + } } - func bottom() -> PinLayoutObjC { - _ = impl?.bottom() - return self + var leftPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.left(percent%) + return self + } } - func bottom(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.bottom(value) - return self + var leftInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.left(insets) + return self + } } - func bottom(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.bottom(percent%) - return self + var bottom: POVoid { + return { [weak self] in + _ = self?.impl?.bottom() + return self + } } - - func bottom(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.bottom(insets) - return self + + var bottomValue: POValue { + return { [weak self] value in + _ = self?.impl?.bottom(value) + return self + } } - func right() -> PinLayoutObjC { - _ = impl?.right() - return self + var bottomPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.bottom(percent%) + return self + } } - func right(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.right(value) - return self + var bottomInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.bottom(insets) + return self + } } - func right(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.right(percent%) - return self + var right: POVoid { + return { [weak self] in + _ = self?.impl?.right() + return self + } } - - func right(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.right(insets) - return self + + var rightValue: POValue { + return { [weak self] value in + _ = self?.impl?.right(value) + return self + } } - func hCenter() -> PinLayoutObjC { - _ = impl?.hCenter() - return self + var rightPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.right(percent%) + return self + } } - func hCenter(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.hCenter(value) - return self + var rightInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.right(insets) + return self + } } - func hCenter(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.hCenter(percent%) - return self + var hCenter: POVoid { + return { [weak self] in + _ = self?.impl?.hCenter() + return self + } } - func vCenter() -> PinLayoutObjC { - _ = impl?.vCenter() - return self + var hCenterValue: POValue { + return { [weak self] value in + _ = self?.impl?.hCenter(value) + return self + } } - func vCenter(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.vCenter(value) - return self + var hCenterPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.hCenter(percent%) + return self + } } - func vCenter(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.vCenter(percent%) - return self + var vCenter: POVoid { + return { [weak self] in + _ = self?.impl?.vCenter() + return self + } } - func start() -> PinLayoutObjC { - _ = impl?.start() - return self + var vCenterValue: POValue { + return { [weak self] value in + _ = self?.impl?.vCenter(value) + return self + } } - func start(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.start(value) - return self + var vCenterPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.vCenter(percent%) + return self + } } - func start(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.start(percent%) - return self + var start: POVoid { + return { [weak self] in + _ = self?.impl?.start() + return self + } } - - func start(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.start(insets) - return self + + var startValue: POValue { + return { [weak self] value in + _ = self?.impl?.start(value) + return self + } } - func end() -> PinLayoutObjC { - _ = impl?.end() - return self + var startPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.start(percent%) + return self + } } - func end(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.end(value) - return self + var startInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.start(insets) + return self + } } - func end(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.end(percent%) - return self + var end: POVoid { + return { [weak self] in + _ = self?.impl?.end() + return self + } } - - func end(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.end(insets) - return self + + var endValue: POValue { + return { [weak self] value in + _ = self?.impl?.end(value) + return self + } } - func top(to edge: VerticalEdge) -> PinLayoutObjC { - _ = impl?.top(to: edge) - return self + var endPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.end(percent%) + return self + } } - func vCenter(to edge: VerticalEdge) -> PinLayoutObjC { - _ = impl?.vCenter(to: edge) - return self + var endInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.end(insets) + return self + } } - func bottom(to edge: VerticalEdge) -> PinLayoutObjC { - _ = impl?.bottom(to: edge) - return self + var all: POVoid { + return { [weak self] in + _ = self?.impl?.all() + return self + } } - func left(to edge: HorizontalEdge) -> PinLayoutObjC { - _ = impl?.left(to: edge) - return self + var horizontally: POVoid { + return { [weak self] in + _ = self?.impl?.horizontally() + return self + } } - func hCenter(to edge: HorizontalEdge) -> PinLayoutObjC { - _ = impl?.hCenter(to: edge) - return self + var vertically: POVoid { + return { [weak self] in + _ = self?.impl?.vertically() + return self + } } - func right(to edge: HorizontalEdge) -> PinLayoutObjC { - _ = impl?.right(to: edge) - return self + var topToEdge: POVEdge { + return { [weak self] edge in + _ = self?.impl?.top(to: edge) + return self + } } - func start(to edge: HorizontalEdge) -> PinLayoutObjC { - _ = impl?.start(to: edge) - return self + var vCenterToEdge: POVEdge { + return { [weak self] edge in + _ = self?.impl?.vCenter(to: edge) + return self + } } - func end(to edge: HorizontalEdge) -> PinLayoutObjC { - _ = impl?.end(to: edge) - return self + var bottomToEdge: POVEdge { + return { [weak self] edge in + _ = self?.impl?.bottom(to: edge) + return self + } } - func all() -> PinLayoutObjC { - _ = impl?.all() - return self + var leftToEdge: POHEdge { + return { [weak self] edge in + _ = self?.impl?.left(to: edge) + return self + } } - func horizontally() -> PinLayoutObjC { - _ = impl?.horizontally() - return self + var hCenterToEdge: POHEdge { + return { [weak self] edge in + _ = self?.impl?.hCenter(to: edge) + return self + } } - - func horizontally(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.horizontally(value) - return self + + var rightToEdge: POHEdge { + return { [weak self] edge in + _ = self?.impl?.right(to: edge) + return self + } } - func vertically() -> PinLayoutObjC { - _ = impl?.vertically() - return self + var startToEdge: POHEdge { + return { [weak self] edge in + _ = self?.impl?.start(to: edge) + return self + } } - - func vertically(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.vertically(value) - return self + + var endToEdge: POHEdge { + return { [weak self] edge in + _ = self?.impl?.end(to: edge) + return self + } } - func topLeft(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.topLeft(to: anchor) - return self + var topLeftToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.topLeft(to: anchor) + return self + } } - func topLeft() -> PinLayoutObjC { - _ = impl?.topLeft() - return self + var topLeft: POVoid { + return { [weak self] in + _ = self?.impl?.topLeft() + return self + } } - func topStart(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.topStart(to: anchor) - return self + var topStartToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.topStart(to: anchor) + return self + } } - func topStart() -> PinLayoutObjC { - _ = impl?.topStart() - return self + var topStart: POVoid { + return { [weak self] in + _ = self?.impl?.topStart() + return self + } } - func topCenter(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.topCenter(to: anchor) - return self + var topCenterToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.topCenter(to: anchor) + return self + } } - func topCenter() -> PinLayoutObjC { - _ = impl?.topCenter() - return self + var topCenter: POVoid { + return { [weak self] in + _ = self?.impl?.topCenter() + return self + } } - func topRight(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.topRight(to: anchor) - return self + var topRightToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.topRight(to: anchor) + return self + } } - func topRight() -> PinLayoutObjC { - _ = impl?.topRight() - return self + var topRight: POVoid { + return { [weak self] in + _ = self?.impl?.topRight() + return self + } } - func topEnd(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.topEnd(to: anchor) - return self + var topEndToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.topEnd(to: anchor) + return self + } } - func topEnd() -> PinLayoutObjC { - _ = impl?.topEnd() - return self + var topEnd: POVoid { + return { [weak self] in + _ = self?.impl?.topEnd() + return self + } } - func centerLeft(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.centerLeft(to: anchor) - return self + var centerLeftToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.centerLeft(to: anchor) + return self + } } - func centerLeft() -> PinLayoutObjC { - _ = impl?.centerLeft() - return self + var centerLeft: POVoid { + return { [weak self] in + _ = self?.impl?.centerLeft() + return self + } } - func centerStart(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.centerStart(to: anchor) - return self + var centerStartToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.centerStart(to: anchor) + return self + } } - func centerStart() -> PinLayoutObjC { - _ = impl?.centerStart() - return self + var centerStart: POVoid { + return { [weak self] in + _ = self?.impl?.centerStart() + return self + } } - func center(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.center(to: anchor) - return self + var centerToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.center(to: anchor) + return self + } } - func center() -> PinLayoutObjC { - _ = impl?.center() - return self + var center: POVoid { + return { [weak self] in + _ = self?.impl?.center() + return self + } } - func centerRight(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.centerRight(to: anchor) - return self + var centerRightToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.centerRight(to: anchor) + return self + } } - func centerRight() -> PinLayoutObjC { - _ = impl?.centerRight() - return self + var centerRight: POVoid { + return { [weak self] in + _ = self?.impl?.centerRight() + return self + } } - func centerEnd(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.centerEnd(to: anchor) - return self + var centerEndToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.centerEnd(to: anchor) + return self + } } - func centerEnd() -> PinLayoutObjC { - _ = impl?.centerEnd() - return self + var centerEnd: POVoid { + return { [weak self] in + _ = self?.impl?.centerEnd() + return self + } } - func bottomLeft(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.bottomLeft(to: anchor) - return self + var bottomLeftToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.bottomLeft(to: anchor) + return self + } } - func bottomLeft() -> PinLayoutObjC { - _ = impl?.bottomLeft() - return self + var bottomLeft: POVoid { + return { [weak self] in + _ = self?.impl?.bottomLeft() + return self + } } - func bottomStart(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.bottomStart(to: anchor) - return self + var bottomStartToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.bottomStart(to: anchor) + return self + } } - func bottomStart() -> PinLayoutObjC { - _ = impl?.bottomStart() - return self + var bottomStart: POVoid { + return { [weak self] in + _ = self?.impl?.bottomStart() + return self + } } - func bottomCenter(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.bottomCenter(to: anchor) - return self + var bottomCenterToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.bottomCenter(to: anchor) + return self + } } - func bottomCenter() -> PinLayoutObjC { - _ = impl?.bottomCenter() - return self + var bottomCenter: POVoid { + return { [weak self] in + _ = self?.impl?.bottomCenter() + return self + } } - func bottomRight(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.bottomRight(to: anchor) - return self + var bottomRightToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.bottomRight(to: anchor) + return self + } } - func bottomRight() -> PinLayoutObjC { - _ = impl?.bottomRight() - return self + var bottomRight: POVoid { + return { [weak self] in + _ = self?.impl?.bottomRight() + return self + } } - func bottomEnd(to anchor: Anchor) -> PinLayoutObjC { - _ = impl?.bottomEnd(to: anchor) - return self + var bottomEndToAnchor: POAnchor { + return { [weak self] anchor in + _ = self?.impl?.bottomEnd(to: anchor) + return self + } } - func bottomEnd() -> PinLayoutObjC { - _ = impl?.bottomEnd() - return self + var bottomEnd: POVoid { + return { [weak self] in + _ = self?.impl?.bottomEnd() + return self + } } - func above(of view: PView) -> PinLayoutObjC { - _ = impl?.above(of: view) - return self + var aboveOf: POView { + return { [weak self] view in + _ = self?.impl?.above(of: view) + return self + } } - func above(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.above(of: views) - return self + var aboveOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.above(of: views) + return self + } } - func above(of view: PView, aligned: HorizontalAlign) -> PinLayoutObjC { - _ = impl?.above(of: view, aligned: aligned) - return self + var aboveOfAligned: POViewHAligned { + return { [weak self] view, aligned in + _ = self?.impl?.above(of: view, aligned: aligned) + return self + } } - func above(ofViews views: [PView], aligned: HorizontalAlign) -> PinLayoutObjC { - _ = impl?.above(of: views, aligned: aligned) - return self + var aboveOfViewsAligned: POViewsHAligned { + return { [weak self] views, aligned in + _ = self?.impl?.above(of: views, aligned: aligned) + return self + } } - func below(of view: PView) -> PinLayoutObjC { - _ = impl?.below(of: view) - return self + var belowOf: POView { + return { [weak self] view in + _ = self?.impl?.below(of: view) + return self + } } - func below(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.below(of: views) - return self + var belowOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.below(of: views) + return self + } } - func below(of view: PView, aligned: HorizontalAlign) -> PinLayoutObjC { - _ = impl?.below(of: view, aligned: aligned) - return self + var belowOfAligned: POViewHAligned { + return { [weak self] view, aligned in + _ = self?.impl?.below(of: view, aligned: aligned) + return self + } } - func below(ofViews views: [PView], aligned: HorizontalAlign) -> PinLayoutObjC { - _ = impl?.below(of: views, aligned: aligned) - return self + var belowOfViewsAligned: POViewsHAligned { + return { [weak self] views, aligned in + _ = self?.impl?.below(of: views, aligned: aligned) + return self + } } - func left(of view: PView) -> PinLayoutObjC { - _ = impl?.left(of: view) - return self + var leftOf: POView { + return { [weak self] view in + _ = self?.impl?.left(of: view) + return self + } } - func left(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.left(of: views) - return self + var leftOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.left(of: views) + return self + } } - func left(of view: PView, aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.left(of: view, aligned: aligned) - return self + var leftOfAligned: POViewVAligned { + return { [weak self] view, aligned in + _ = self?.impl?.left(of: view, aligned: aligned) + return self + } } - func left(ofViews views: [PView], aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.left(of: views, aligned: aligned) - return self + var leftOfViewsAligned: POViewsVAligned { + return { [weak self] views, aligned in + _ = self?.impl?.left(of: views, aligned: aligned) + return self + } } - func right(of view: PView) -> PinLayoutObjC { - _ = impl?.right(of: view) - return self + var rightOf: POView { + return { [weak self] view in + _ = self?.impl?.right(of: view) + return self + } } - func right(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.right(of: views) - return self + var rightOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.right(of: views) + return self + } } - func right(of view: PView, aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.right(of: view, aligned: aligned) - return self + var rightOfAligned: POViewVAligned { + return { [weak self] view, aligned in + _ = self?.impl?.right(of: view, aligned: aligned) + return self + } } - func right(ofViews views: [PView], aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.right(of: views, aligned: aligned) - return self + var rightOfViewsAligned: POViewsVAligned { + return { [weak self] views, aligned in + _ = self?.impl?.right(of: views, aligned: aligned) + return self + } } - func before(of view: PView) -> PinLayoutObjC { - _ = impl?.before(of: view) - return self + var beforeOf: POView { + return { [weak self] view in + _ = self?.impl?.before(of: view) + return self + } } - func before(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.before(of: views) - return self + var beforeOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.before(of: views) + return self + } } - func before(of view: PView, aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.before(of: view, aligned: aligned) - return self + var beforeOfAligned: POViewVAligned { + return { [weak self] view, aligned in + _ = self?.impl?.before(of: view, aligned: aligned) + return self + } } - func before(ofViews views: [PView], aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.before(of: views, aligned: aligned) - return self + var beforeOfViewsAligned: POViewsVAligned { + return { [weak self] views, aligned in + _ = self?.impl?.before(of: views, aligned: aligned) + return self + } } - func after(of view: PView) -> PinLayoutObjC { - _ = impl?.after(of: view) - return self + var afterOf: POView { + return { [weak self] view in + _ = self?.impl?.after(of: view) + return self + } } - func after(ofViews views: [PView]) -> PinLayoutObjC { - _ = impl?.after(of: views) - return self + var afterOfViews: POViews { + return { [weak self] views in + _ = self?.impl?.after(of: views) + return self + } } - func after(of view: PView, aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.after(of: view, aligned: aligned) - return self + var afterOfAligned: POViewVAligned { + return { [weak self] view, aligned in + _ = self?.impl?.after(of: view, aligned: aligned) + return self + } } - func after(ofViews views: [PView], aligned: VerticalAlign) -> PinLayoutObjC { - _ = impl?.after(of: views, aligned: aligned) - return self + var afterOfViewsAligned: POViewsVAligned { + return { [weak self] views, aligned in + _ = self?.impl?.after(of: views, aligned: aligned) + return self + } } - func justify(_ align: HorizontalAlign) -> PinLayoutObjC { - _ = impl?.justify(align) - return self + var justify: POHAlign { + return { [weak self] align in + _ = self?.impl?.justify(align) + return self + } } - func align(_ align: VerticalAlign) -> PinLayoutObjC { - _ = impl?.align(align) - return self + var align: POVAlign { + return { [weak self] align in + _ = self?.impl?.align(align) + return self + } } - func width(_ width: CGFloat) -> PinLayoutObjC { - _ = impl?.width(width) - return self + var width: POValue { + return { [weak self] value in + _ = self?.impl?.width(value) + return self + } } - func width(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.width(percent%) - return self + var widthPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.width(percent%) + return self + } } - func width(of view: PView) -> PinLayoutObjC { - _ = impl?.width(of: view) - return self + var widthOf: POView { + return { [weak self] view in + _ = self?.impl?.width(of: view) + return self + } } - func minWidth(_ width: CGFloat) -> PinLayoutObjC { - _ = impl?.minWidth(width) - return self + var minWidth: POValue { + return { [weak self] value in + _ = self?.impl?.minWidth(value) + return self + } } - func minWidth(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.minWidth(percent%) - return self + var minWidthPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.minWidth(percent%) + return self + } } - func maxWidth(_ width: CGFloat) -> PinLayoutObjC { - _ = impl?.maxWidth(width) - return self + var maxWidth: POValue { + return { [weak self] value in + _ = self?.impl?.maxWidth(value) + return self + } } - func maxWidth(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.maxWidth(percent%) - return self + var maxWidthPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.maxWidth(percent%) + return self + } } - func height(_ height: CGFloat) -> PinLayoutObjC { - _ = impl?.height(height) - return self + var height: POValue { + return { [weak self] value in + _ = self?.impl?.height(value) + return self + } } - func height(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.height(percent%) - return self + var heightPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.height(percent%) + return self + } } - func height(of view: PView) -> PinLayoutObjC { - _ = impl?.height(of: view) - return self + var heightOf: POView { + return { [weak self] view in + _ = self?.impl?.height(of: view) + return self + } } - func minHeight(_ height: CGFloat) -> PinLayoutObjC { - _ = impl?.minHeight(height) - return self + var minHeight: POValue { + return { [weak self] value in + _ = self?.impl?.minHeight(value) + return self + } } - func minHeight(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.minHeight(percent%) - return self + var minHeightPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.minHeight(percent%) + return self + } } - func maxHeight(_ height: CGFloat) -> PinLayoutObjC { - _ = impl?.maxHeight(height) - return self + var maxHeight: POValue { + return { [weak self] value in + _ = self?.impl?.maxHeight(value) + return self + } } - func maxHeight(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.maxHeight(percent%) - return self + var maxHeightPercent: POValue { + return { [weak self] percent in + _ = self?.impl?.maxHeight(percent%) + return self + } } - func size(_ size: CGSize) -> PinLayoutObjC { - _ = impl?.size(size) - return self + var size: POSize { + return { [weak self] size in + _ = self?.impl?.size(size) + return self + } } - func size(length: CGFloat) -> PinLayoutObjC { - _ = impl?.size(length) - return self + var sizeLength: POValue { + return { [weak self] value in + _ = self?.impl?.size(value) + return self + } } - func size(percent: CGFloat) -> PinLayoutObjC { - _ = impl?.size(percent%) - return self + var sizePercent: POValue { + return { [weak self] percent in + _ = self?.impl?.size(percent%) + return self + } } - func size(of view: PView) -> PinLayoutObjC { - _ = impl?.size(of: view) - return self + var sizeOf: POView { + return { [weak self] view in + _ = self?.impl?.size(of: view) + return self + } } - func wrapContent() -> PinLayoutObjC { - _ = impl?.wrapContent() - return self + var wrapContent: POVoid { + return { [weak self] in + _ = self?.impl?.wrapContent() + return self + } } - func wrapContent(padding: CGFloat) -> PinLayoutObjC { - _ = impl?.wrapContent(padding: padding) - return self + var wrapContentPadding: POValue { + return { [weak self] value in + _ = self?.impl?.wrapContent(padding: value) + return self + } } - func wrapContent(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.wrapContent(padding: insets) - return self + var wrapContentInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.wrapContent(padding: insets) + return self + } } - func wrapContent(type: WrapType) -> PinLayoutObjC { - _ = impl?.wrapContent(type) - return self + var wrapContentType: POWrapType { + return { [weak self] type in + _ = self?.impl?.wrapContent(type) + return self + } } - func wrapContent(type: WrapType, padding: CGFloat) -> PinLayoutObjC { - _ = impl?.wrapContent(type, padding: padding) - return self + var wrapContentTypePadding: POWrapTypePadding { + return { [weak self] type, value in + _ = self?.impl?.wrapContent(type, padding: value) + return self + } } - func wrapContent(type: WrapType, insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.wrapContent(type, padding: insets) - return self + var wrapContentTypeInsets: POWrapTypeInsets { + return { [weak self] type, insets in + _ = self?.impl?.wrapContent(type, padding: insets) + return self + } } - func aspectRatio(_ ratio: CGFloat) -> PinLayoutObjC { - _ = impl?.aspectRatio(ratio) - return self + var aspectRatioValue: POValue { + return { [weak self] value in + _ = self?.impl?.aspectRatio(value) + return self + } } - func aspectRatio(of view: PView) -> PinLayoutObjC { - _ = impl?.aspectRatio(of: view) - return self + var aspectRatioOf: POView { + return { [weak self] view in + _ = self?.impl?.aspectRatio(of: view) + return self + } } - + #if os(iOS) || os(tvOS) - func aspectRatio() -> PinLayoutObjC { - _ = impl?.aspectRatio() - return self + var aspectRatio: POVoid { + return { [weak self] in + _ = self?.impl?.aspectRatio() + return self + } } #endif - - func sizeToFit() -> PinLayoutObjC { - return sizeToFit(.content) + + var sizeToFit: POVoid { + return { [weak self] in + _ = self?.impl?.sizeToFit() + return self + } } - - func sizeToFit(_ fitType: Fit) -> PinLayoutObjC { - let type: FitType - switch fitType { - case .width: type = .width - case .height: type = .height - case .widthFlexible: type = .widthFlexible - case .heightFlexible: type = .heightFlexible - case .content: type = .content + + var sizeToFitType: POFitType { + return { [weak self] fitType in + let type: FitType + switch fitType { + case .width: type = .width + case .height: type = .height + case .widthFlexible: type = .widthFlexible + case .heightFlexible: type = .heightFlexible + case .content: type = .content + } + _ = self?.impl?.sizeToFit(type) + return self } - _ = impl?.sizeToFit(type) - return self } - func marginTop(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginTop(value) - return self + var marginTop: POValue { + return { [weak self] value in + _ = self?.impl?.marginTop(value) + return self + } } - func marginLeft(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginLeft(value) - return self + var marginLeft: POValue { + return { [weak self] value in + _ = self?.impl?.marginLeft(value) + return self + } } - func marginBottom(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginBottom(value) - return self + var marginBottom: POValue { + return { [weak self] value in + _ = self?.impl?.marginBottom(value) + return self + } } - func marginRight(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginRight(value) - return self + var marginRight: POValue { + return { [weak self] value in + _ = self?.impl?.marginRight(value) + return self + } } - func marginStart(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginStart(value) - return self + var marginStart: POValue { + return { [weak self] value in + _ = self?.impl?.marginStart(value) + return self + } } - func marginEnd(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginEnd(value) - return self + var marginEnd: POValue { + return { [weak self] value in + _ = self?.impl?.marginEnd(value) + return self + } } - func marginHorizontal(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginHorizontal(value) - return self + var marginHorizontal: POValue { + return { [weak self] value in + _ = self?.impl?.marginHorizontal(value) + return self + } } - func marginVertical(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.marginVertical(value) - return self + var marginVertical: POValue { + return { [weak self] value in + _ = self?.impl?.marginVertical(value) + return self + } } - func margin(insets: PEdgeInsets) -> PinLayoutObjC { - _ = impl?.margin(insets) - return self + var marginInsets: POEdgeInsets { + return { [weak self] insets in + _ = self?.impl?.margin(insets) + return self + } } - func margin(_ value: CGFloat) -> PinLayoutObjC { - _ = impl?.margin(value) - return self + var margin: POValue { + return { [weak self] value in + _ = self?.impl?.margin(value) + return self + } } - func margin(vertical: CGFloat, horizontal: CGFloat) -> PinLayoutObjC { - _ = impl?.margin(vertical, horizontal) - return self + var marginVH: (CGFloat, CGFloat) -> PinLayoutObjC? { + return { [weak self] vertical, horizontal in + _ = self?.impl?.margin(vertical, horizontal) + return self + } } - func margin(top: CGFloat, horizontal: CGFloat, bottom: CGFloat) -> PinLayoutObjC { - _ = impl?.margin(top, horizontal, bottom) - return self + var marginTHB: (CGFloat, CGFloat, CGFloat) -> PinLayoutObjC? { + return { [weak self] top, horizontal, bottom in + _ = self?.impl?.margin(top, horizontal, bottom) + return self + } } - func margin(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> PinLayoutObjC { - _ = impl?.margin(top, left, bottom, right) - return self + var marginTLBR: (CGFloat, CGFloat, CGFloat, CGFloat) -> PinLayoutObjC? { + return { [weak self] top, left, bottom, right in + _ = self?.impl?.margin(top, left, bottom, right) + return self + } } - func pinEdges() -> PinLayoutObjC { - _ = impl?.pinEdges() - return self + var pinEdges: POVoid { + return { [weak self] in + _ = self?.impl?.pinEdges() + return self + } } } diff --git a/TestProjects/carthage/ios/PinLayout-Carthage-iOS/TestObjectiveC.m b/TestProjects/carthage/ios/PinLayout-Carthage-iOS/TestObjectiveC.m index 92ddde9d..912ab314 100644 --- a/TestProjects/carthage/ios/PinLayout-Carthage-iOS/TestObjectiveC.m +++ b/TestProjects/carthage/ios/PinLayout-Carthage-iOS/TestObjectiveC.m @@ -45,10 +45,10 @@ - (id)initWithFrame:(CGRect)frame { - (void) layoutSubviews { [super layoutSubviews]; - [[[[[[logo.pinObjc top] left] width:100] aspectRatio] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout]; - [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] right] marginHorizontal:10] layout]; - [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] sizeToFit:FitWidth] layout]; - [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:10] layout]; +// logo.pinObjc.top().left().width(100).aspectRatio().marginTHB(topLayoutGuide + 10, 10, 10).layout(); +// segmented.pinObjc.rightOfAligned(logo, VerticalAlignTop).right().marginHorizontal(10).layout(); +// textLabel.pinObjc.belowOfAligned(segmented, HorizontalAlignLeft).widthOf(segmented).pinEdges().marginTop(10).sizeToFitType(FitWidth).layout(); +// separatorView.pinObjc.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft).rightToEdge(segmented.edge.right).height(1).marginTop(10).layout(); } @end diff --git a/TestProjects/cocoapods/ios/PinLayout-iOS/TestObjectiveC.m b/TestProjects/cocoapods/ios/PinLayout-iOS/TestObjectiveC.m index 92ddde9d..6d612a7f 100644 --- a/TestProjects/cocoapods/ios/PinLayout-iOS/TestObjectiveC.m +++ b/TestProjects/cocoapods/ios/PinLayout-iOS/TestObjectiveC.m @@ -45,10 +45,10 @@ - (id)initWithFrame:(CGRect)frame { - (void) layoutSubviews { [super layoutSubviews]; - [[[[[[logo.pinObjc top] left] width:100] aspectRatio] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout]; - [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] right] marginHorizontal:10] layout]; - [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] sizeToFit:FitWidth] layout]; - [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:10] layout]; + logo.pinObjc.top().left().width(100).aspectRatio().marginTHB(topLayoutGuide + 10, 10, 10).layout(); + segmented.pinObjc.rightOfAligned(logo, VerticalAlignTop).right().marginHorizontal(10).layout(); + textLabel.pinObjc.belowOfAligned(segmented, HorizontalAlignLeft).widthOf(segmented).pinEdges().marginTop(10).sizeToFitType(FitWidth).layout(); + separatorView.pinObjc.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft).rightToEdge(segmented.edge.right).height(1).marginTop(10).layout(); } @end diff --git a/TestProjects/cocoapods/macos/PinLayout-macOS/TestObjectiveC.m b/TestProjects/cocoapods/macos/PinLayout-macOS/TestObjectiveC.m index 914b14d9..60042b58 100644 --- a/TestProjects/cocoapods/macos/PinLayout-macOS/TestObjectiveC.m +++ b/TestProjects/cocoapods/macos/PinLayout-macOS/TestObjectiveC.m @@ -27,8 +27,8 @@ - (id)initWithFrame:(CGRect)frame { - (void)layout { [super layout]; - [[[[[logo.pinObjc top] left] width:100] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout]; - [[[[separatorView.pinObjc belowOf:logo aligned:HorizontalAlignLeft] height:1] marginTop:10] layout]; + logo.pinObjc.top().left().width(100).marginTHB(topLayoutGuide + 10, 10, 10).layout(); + separatorView.pinObjc.belowOfAligned(logo, HorizontalAlignLeft).height(1).marginTop(10).layout(); } @end diff --git a/TestProjects/cocoapods/tvos/PinLayout-tvOS/TestObjectiveC.m b/TestProjects/cocoapods/tvos/PinLayout-tvOS/TestObjectiveC.m index 92ddde9d..6d612a7f 100644 --- a/TestProjects/cocoapods/tvos/PinLayout-tvOS/TestObjectiveC.m +++ b/TestProjects/cocoapods/tvos/PinLayout-tvOS/TestObjectiveC.m @@ -45,10 +45,10 @@ - (id)initWithFrame:(CGRect)frame { - (void) layoutSubviews { [super layoutSubviews]; - [[[[[[logo.pinObjc top] left] width:100] aspectRatio] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout]; - [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] right] marginHorizontal:10] layout]; - [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] sizeToFit:FitWidth] layout]; - [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:10] layout]; + logo.pinObjc.top().left().width(100).aspectRatio().marginTHB(topLayoutGuide + 10, 10, 10).layout(); + segmented.pinObjc.rightOfAligned(logo, VerticalAlignTop).right().marginHorizontal(10).layout(); + textLabel.pinObjc.belowOfAligned(segmented, HorizontalAlignLeft).widthOf(segmented).pinEdges().marginTop(10).sizeToFitType(FitWidth).layout(); + separatorView.pinObjc.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft).rightToEdge(segmented.edge.right).height(1).marginTop(10).layout(); } @end diff --git a/Tests/Common/ObjectiveCSpec.m b/Tests/Common/ObjectiveCSpec.m index 34c2dd4b..208b95a2 100644 --- a/Tests/Common/ObjectiveCSpec.m +++ b/Tests/Common/ObjectiveCSpec.m @@ -64,24 +64,23 @@ it(@"using Pin.logMissingLayoutCalls", ^{ Pin.logMissingLayoutCalls = true; - [[aView pinObjc] top:10]; + aView.pinObjc.topValue(10); //expect(Pin.lastWarningText).to(contain(@"PinLayout commands have been issued without calling the 'layout()' method to complete the layout")); }); it(@"using Pin.logMissingLayoutCalls set to false", ^{ Pin.logMissingLayoutCalls = false; - [[[aView pinObjc] top:10] layout]; + aView.pinObjc.topValue(10).layout(); expect(@(aView.frame)).to(equal(@(CGRectMake(40, 10, 100, 60)))); expect(Pin.lastWarningText).to(beNil()); }); it(@"check the access to PinLayout methods from objective-c", ^{ - [[[rootView pinObjc] wrapContent] layout]; - [[[rootView pinObjc] wrapContentWithType:WrapTypeVertically] layout]; - [[[rootView pinObjc] wrapContentWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)] layout]; - [[[rootView pinObjc] wrapContentWithType:WrapTypeAll insets:UIEdgeInsetsMake(0, 0, 0, 0)] layout]; - [[[rootView pinObjc] wrapContentWithPadding:10] layout]; - [[[rootView pinObjc] wrapContentWithType:WrapTypeHorizontally padding:10] layout]; + rootView.pinObjc.wrapContent().layout(); + rootView.pinObjc.wrapContentInsets(UIEdgeInsetsMake(0, 0, 0, 0)).layout(); + rootView.pinObjc.wrapContentTypeInsets(WrapTypeAll, UIEdgeInsetsMake(0, 0, 0, 0)).layout(); + rootView.pinObjc.wrapContentPadding(10).layout(); + rootView.pinObjc.wrapContentTypePadding(WrapTypeHorizontally, 10).layout(); }); }); }); diff --git a/docs/objective_c.md b/docs/objective_c.md index 328522a8..6c17b258 100644 --- a/docs/objective_c.md +++ b/docs/objective_c.md @@ -14,11 +14,14 @@ This example implement the PinLayout's Intro example using objective-c ``` - (void) layoutSubviews { [super layoutSubviews]; - - [[[[[[logo.pinObjc top] left] width:100] aspectRatio] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout]; - [[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] right] marginHorizontal:10] layout]; - [[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] fitSize] layout]; - [[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:10] layout]; + + CGFloat margin = 10; + UIEdgeInsets safeArea = self.pinObjc.safeArea; + + logo.pinObjc.topInsets(safeArea).leftInsets(safeArea).width(100).aspectRatio().margin(margin).layout(); + segmented.pinObjc.rightOfAligned(logo, VerticalAlignTop).rightInsets(safeArea).marginHorizontal(margin).layout(); + textLabel.pinObjc.belowOfAligned(segmented, HorizontalAlignLeft).widthOf(segmented).pinEdges().marginTop(margin).sizeToFitType(FitWidth).layout(); + separatorView.pinObjc.belowOfViewsAligned(@[logo, textLabel], HorizontalAlignLeft).rightToEdge(segmented.edge.right).height(1).marginTop(margin).layout(); } ``` @@ -31,7 +34,7 @@ This example implement the PinLayout's Intro example using objective-c The PinLayout's objective-c interface is available using the property `pinObjc` (instead of `pin` in Swift) ``` - [[view.pinObjc top] layout]; + view.pinObjc.top().layout(); ``` #### `layout()` @@ -47,6 +50,6 @@ When using the Objective-c interface, the `layout` method must be called explici view.pin.width(100) // Objective-c - [[view.pinObjc width:100] layout]; + view.pinObjc.width(100).layout(); ```