From e20a081173044e22e6024e7930dcca9f85eedf79 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Thu, 28 Mar 2024 17:53:19 +0200 Subject: [PATCH 01/10] Fix wrap content calculation by filter hidden views --- Sources/PinLayout+WrapContent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index e58731c..af0513e 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -101,7 +101,7 @@ extension PinLayout { } private func wrapContent(_ type: WrapType, padding: PEdgeInsets, _ context: Context) -> PinLayout { - let subviews = view.subviews + let subviews = view.subviews.filter { !$0.isHidden } guard !subviews.isEmpty else { return self } let firstViewRect = subviews[0].getRect(keepTransform: keepTransform) From 98258f81f139937046ba059ea03cf3562d52c9d9 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Thu, 28 Mar 2024 19:41:32 +0200 Subject: [PATCH 02/10] Fix wrap content calculation by filter hidden views --- Sources/Layoutable.swift | 1 + Sources/PinLayout+WrapContent.swift | 35 +++++++++++++++++------------ Sources/Types.swift | 7 ++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index fa4e996..0fa3b2e 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -28,6 +28,7 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { var superview: PinView? { get } var subviews: [PinView] { get } + var isHidden: Bool { get } func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index af0513e..734d3cc 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -28,8 +28,8 @@ extension PinLayout { Adjust the view's width & height to wrap all its subviews. The method also adjust subviews position to create a tight wrap. */ @discardableResult - public func wrapContent() -> PinLayout { - return wrapContent(.all, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), { return "wrapContent()" }) + public func wrapContent(viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(.all, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), viewFilter: viewFilter, { return "wrapContent()" }) } /** @@ -39,8 +39,8 @@ extension PinLayout { - padding: Specify a padding value. */ @discardableResult - public func wrapContent(padding: CGFloat) -> PinLayout { - return wrapContent(.all, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), { return "wrapContent(padding: \(padding)" }) + public func wrapContent(padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(.all, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), viewFilter: viewFilter, { return "wrapContent(padding: \(padding)" }) } /** @@ -53,8 +53,8 @@ extension PinLayout { - padding: Specify a padding using an UIEdgeInsets. */ @discardableResult - public func wrapContent(padding: PEdgeInsets) -> PinLayout { - return wrapContent(.all, padding: padding, { return "wrapContent(padding: \(insetsDescription(padding))" }) + public func wrapContent(padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(.all, padding: padding, viewFilter: viewFilter, { return "wrapContent(padding: \(insetsDescription(padding))" }) } /** @@ -66,8 +66,8 @@ extension PinLayout { - type: Specify the wrap type (.all, .horizontally, .vertically) */ @discardableResult - public func wrapContent(_ type: WrapType) -> PinLayout { - return wrapContent(type, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), { return "wrapContent(\(type.description)" }) + public func wrapContent(_ type: WrapType, viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(type, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), viewFilter: viewFilter, { return "wrapContent(\(type.description)" }) } /** @@ -81,8 +81,8 @@ extension PinLayout { - padding: Specify a padding value. */ @discardableResult - public func wrapContent(_ type: WrapType, padding: CGFloat) -> PinLayout { - return wrapContent(type, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), { return "wrapContent(\(type.description), padding: \(padding)" }) + public func wrapContent(_ type: WrapType, padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(type, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), viewFilter: viewFilter, { return "wrapContent(\(type.description), padding: \(padding)" }) } /** @@ -96,12 +96,19 @@ extension PinLayout { - padding: Specify a padding using an UIEdgeInsets. */ @discardableResult - public func wrapContent(_ type: WrapType, padding: PEdgeInsets) -> PinLayout { - return wrapContent(type, padding: padding, { return "wrapContent(\(type.description), padding: \(insetsDescription(padding))" }) + public func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { + return wrapContent(type, padding: padding, viewFilter: viewFilter, { return "wrapContent(\(type.description), padding: \(insetsDescription(padding))" }) } - private func wrapContent(_ type: WrapType, padding: PEdgeInsets, _ context: Context) -> PinLayout { - let subviews = view.subviews.filter { !$0.isHidden } + private func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .none, _ context: Context) -> PinLayout { + let subviews: [PinView.PinView] + switch viewFilter { + case .visibleOnly: + subviews = view.subviews.filter { !$0.isHidden } + default: + subviews = view.subviews + } + guard !subviews.isEmpty else { return self } let firstViewRect = subviews[0].getRect(keepTransform: keepTransform) diff --git a/Sources/Types.swift b/Sources/Types.swift index 90ab6bb..a75307c 100644 --- a/Sources/Types.swift +++ b/Sources/Types.swift @@ -194,6 +194,13 @@ public enum FitType { case vertically } +@objc public enum ViewFilter: Int { + /// No filter, use all views + case none + /// Consider only views where `hidden` is false + case visibleOnly +} + @objc public enum LayoutDirection: Int { case auto case ltr From fb3a3753afdd128f53685e902ae4d9d07bf86e4e Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Thu, 28 Mar 2024 19:48:37 +0200 Subject: [PATCH 03/10] Add comments --- Sources/PinLayout+WrapContent.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index 734d3cc..f654ccb 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -26,6 +26,9 @@ import AppKit extension PinLayout { /** Adjust the view's width & height to wrap all its subviews. The method also adjust subviews position to create a tight wrap. + + - Parameters: + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(viewFilter: ViewFilter = .none) -> PinLayout { @@ -37,6 +40,7 @@ extension PinLayout { - Parameters: - padding: Specify a padding value. + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { @@ -51,6 +55,7 @@ extension PinLayout { - Parameters: - padding: Specify a padding using an UIEdgeInsets. + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { @@ -64,6 +69,7 @@ extension PinLayout { - Parameters: - type: Specify the wrap type (.all, .horizontally, .vertically) + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(_ type: WrapType, viewFilter: ViewFilter = .none) -> PinLayout { @@ -79,6 +85,7 @@ extension PinLayout { - Parameters: - type: Specify the wrap type (.all, .horizontally, .vertically) - padding: Specify a padding value. + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(_ type: WrapType, padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { @@ -94,6 +101,7 @@ extension PinLayout { - Parameters: - type: Specify the wrap type (.all, .horizontally, .vertically) - padding: Specify a padding using an UIEdgeInsets. + - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult public func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { From 7d756bcc26fc9aab3b78590a2a814c297c78f75a Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Thu, 28 Mar 2024 19:52:37 +0200 Subject: [PATCH 04/10] minor fixes --- Sources/PinLayout+WrapContent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index f654ccb..1f2cd8e 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -113,7 +113,7 @@ extension PinLayout { switch viewFilter { case .visibleOnly: subviews = view.subviews.filter { !$0.isHidden } - default: + case .none: subviews = view.subviews } From 6d8120408f0cb0b716248691434911c2668f0234 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Fri, 29 Mar 2024 00:03:14 +0200 Subject: [PATCH 05/10] minor fixes --- Sources/Extensions/CALayer+PinLayout.swift | 4 ++++ Sources/Layoutable.swift | 2 ++ Sources/PinLayout+WrapContent.swift | 4 ++-- Sources/Types.swift | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/Extensions/CALayer+PinLayout.swift b/Sources/Extensions/CALayer+PinLayout.swift index 7eb92be..3bec05f 100644 --- a/Sources/Extensions/CALayer+PinLayout.swift +++ b/Sources/Extensions/CALayer+PinLayout.swift @@ -22,6 +22,10 @@ import QuartzCore extension CALayer: Layoutable { public typealias PinView = CALayer + public var alpha: CGFloat { + CGFloat(opacity) + } + public var superview: CALayer? { return superlayer } diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index 0fa3b2e..787c15d 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -28,7 +28,9 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { var superview: PinView? { get } var subviews: [PinView] { get } + var isHidden: Bool { get } + var alpha: CGFloat { get } func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index 1f2cd8e..cbf69f3 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -108,11 +108,11 @@ extension PinLayout { return wrapContent(type, padding: padding, viewFilter: viewFilter, { return "wrapContent(\(type.description), padding: \(insetsDescription(padding))" }) } - private func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .none, _ context: Context) -> PinLayout { + private func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter, _ context: Context) -> PinLayout { let subviews: [PinView.PinView] switch viewFilter { case .visibleOnly: - subviews = view.subviews.filter { !$0.isHidden } + subviews = view.subviews.filter { !$0.isHidden && $0.alpha > 0 } case .none: subviews = view.subviews } diff --git a/Sources/Types.swift b/Sources/Types.swift index a75307c..c525202 100644 --- a/Sources/Types.swift +++ b/Sources/Types.swift @@ -197,7 +197,7 @@ public enum FitType { @objc public enum ViewFilter: Int { /// No filter, use all views case none - /// Consider only views where `hidden` is false + /// Consider only visible views (isHidden is false and alpha is > 0) case visibleOnly } From 69903d51038038db4f376e82f748a18fd51cf1d4 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Fri, 29 Mar 2024 00:54:27 +0200 Subject: [PATCH 06/10] minor fixes --- Sources/Extensions/CALayer+PinLayout.swift | 8 ++++---- Sources/Extensions/NSView+PinLayout.swift | 4 ++++ Sources/Extensions/UIView+PinLayout.swift | 4 ++++ Sources/Layoutable.swift | 3 +-- Sources/PinLayout+WrapContent.swift | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Sources/Extensions/CALayer+PinLayout.swift b/Sources/Extensions/CALayer+PinLayout.swift index 3bec05f..8385471 100644 --- a/Sources/Extensions/CALayer+PinLayout.swift +++ b/Sources/Extensions/CALayer+PinLayout.swift @@ -22,10 +22,6 @@ import QuartzCore extension CALayer: Layoutable { public typealias PinView = CALayer - public var alpha: CGFloat { - CGFloat(opacity) - } - public var superview: CALayer? { return superlayer } @@ -34,6 +30,10 @@ extension CALayer: Layoutable { return sublayers ?? [] } + public var isVisible: Bool { + !isHidden && opacity > 0 + } + public var pin: PinLayout { return PinLayout(view: self, keepTransform: true) } diff --git a/Sources/Extensions/NSView+PinLayout.swift b/Sources/Extensions/NSView+PinLayout.swift index ee81f9a..722fadd 100644 --- a/Sources/Extensions/NSView+PinLayout.swift +++ b/Sources/Extensions/NSView+PinLayout.swift @@ -33,6 +33,10 @@ extension NSView: Layoutable { return PinLayout(view: self, keepTransform: false) } + public var isVisible: Bool { + !isHidden && alphaValue > 0 + } + @objc public var pinObjc: PinLayoutObjC { return PinLayoutObjCImpl(view: self, keepTransform: true) } diff --git a/Sources/Extensions/UIView+PinLayout.swift b/Sources/Extensions/UIView+PinLayout.swift index 1a9c144..ffa5084 100644 --- a/Sources/Extensions/UIView+PinLayout.swift +++ b/Sources/Extensions/UIView+PinLayout.swift @@ -37,6 +37,10 @@ extension UIView: Layoutable, SizeCalculable { return PinLayoutObjCImpl(view: self, keepTransform: true) } + public var isVisible: Bool { + !isHidden && alpha > 0 + } + public func getRect(keepTransform: Bool) -> CGRect { guard !Pin.autoSizingInProgress || autoSizingRect == nil else { return autoSizingRect ?? CGRect.zero } diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index 787c15d..d611180 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -29,8 +29,7 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { var superview: PinView? { get } var subviews: [PinView] { get } - var isHidden: Bool { get } - var alpha: CGFloat { get } + var isVisible: Bool { get } func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index cbf69f3..bf82a1f 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -112,7 +112,7 @@ extension PinLayout { let subviews: [PinView.PinView] switch viewFilter { case .visibleOnly: - subviews = view.subviews.filter { !$0.isHidden && $0.alpha > 0 } + subviews = view.subviews.filter { $0.isVisible } case .none: subviews = view.subviews } From 46e93fa7be29ffb597996ca5d696e7937e343345 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Fri, 29 Mar 2024 01:01:43 +0200 Subject: [PATCH 07/10] update README.md --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 47045d2..a728f9d 100644 --- a/README.md +++ b/README.md @@ -1371,20 +1371,24 @@ The following methods are useful to adjust view's width and/or height to wrap al **Methods:** -* **`wrapContent()`** -**`wrapContent(padding: CGFloat)`** -**`wrapContent(padding: UIEdgeInsets)`** -Adjust the view's width and height to wrap all its subviews. The method also adjusts subviews's position to create a tight wrap. It is also possible to specify an optional padding around all subviews. -* **`wrapContent(:WrapType)`** -**`wrapContent(:WrapType, padding: CGFloat)`** **`wrapContent(:WrapType, padding: UIEdgeInsets)`** -Adjust the view's width AND/OR height to wrap all its subviews. Accept a WrapType parameter to define the wrapping type. It is also possible to specify an optional padding around all subviews. - +* **`wrapContent(viewFilter: ViewFilter = .none)`** +**`wrapContent(padding: CGFloat, viewFilter: ViewFilter = .none)`** +**`wrapContent(padding: UIEdgeInsets, viewFilter: ViewFilter = .none)`** +Adjust the view's width and height to wrap all its subviews. The method also adjusts subviews's position to create a tight wrap. It is also possible to specify an optional padding around all subviews. Additionally, it's possible to specify whether to include all views or only visible ones. +* **`wrapContent(:WrapType, viewFilter: ViewFilter = .none)`** **`wrapContent(:WrapType, padding: UIEdgeInsets, viewFilter: ViewFilter = .none)`** +**`wrapContent(:WrapType, padding: CGFloat, viewFilter: ViewFilter = .none)`** +Adjust the view's width AND/OR height to wrap all its subviews. Accept a WrapType parameter to define the wrapping type. It is also possible to specify an optional padding around all subviews. Additionally, it's possible to specify whether to include all views or only visible ones. + **Types:** * **`WrapType`** values: * `.horizontally`: Adjust the view's width and update subviews's horizontal position. * `.vertically`: Adjust only the view's height and update subviews's vertical position. * `.all`: Adjust the view's width AND height and update subviews position. This is the default WrapType parameter value `wrapContent()` methods. + +* **`ViewFilter`** values: + * `.none`: No filter, use all views + * `.visibleOnly`: Consider only visible views (isHidden is false and alpha is > 0) ###### Usage examples: ```swift From 44697d4e6b1282337b49ff00778a94ebebe21633 Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Fri, 5 Apr 2024 20:23:02 +0300 Subject: [PATCH 08/10] minor fixes --- Sources/Extensions/CALayer+PinLayout.swift | 4 ++-- Sources/Extensions/NSView+PinLayout.swift | 4 ++-- Sources/Extensions/UIView+PinLayout.swift | 4 ++-- Sources/Layoutable.swift | 2 +- Sources/PinLayout+WrapContent.swift | 16 ++++++++-------- Sources/Types.swift | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/Extensions/CALayer+PinLayout.swift b/Sources/Extensions/CALayer+PinLayout.swift index 8385471..3d9e64a 100644 --- a/Sources/Extensions/CALayer+PinLayout.swift +++ b/Sources/Extensions/CALayer+PinLayout.swift @@ -30,8 +30,8 @@ extension CALayer: Layoutable { return sublayers ?? [] } - public var isVisible: Bool { - !isHidden && opacity > 0 + public var isConsideredVisibleForViewFilters: Bool { + return !isHidden && opacity > 0 } public var pin: PinLayout { diff --git a/Sources/Extensions/NSView+PinLayout.swift b/Sources/Extensions/NSView+PinLayout.swift index 722fadd..fb966d4 100644 --- a/Sources/Extensions/NSView+PinLayout.swift +++ b/Sources/Extensions/NSView+PinLayout.swift @@ -33,8 +33,8 @@ extension NSView: Layoutable { return PinLayout(view: self, keepTransform: false) } - public var isVisible: Bool { - !isHidden && alphaValue > 0 + public var isConsideredVisibleForViewFilters: Bool { + return !isHidden && alphaValue > 0 } @objc public var pinObjc: PinLayoutObjC { diff --git a/Sources/Extensions/UIView+PinLayout.swift b/Sources/Extensions/UIView+PinLayout.swift index ffa5084..a1bb5f1 100644 --- a/Sources/Extensions/UIView+PinLayout.swift +++ b/Sources/Extensions/UIView+PinLayout.swift @@ -37,8 +37,8 @@ extension UIView: Layoutable, SizeCalculable { return PinLayoutObjCImpl(view: self, keepTransform: true) } - public var isVisible: Bool { - !isHidden && alpha > 0 + public var isConsideredVisibleForViewFilters: Bool { + return !isHidden && alpha > 0 } public func getRect(keepTransform: Bool) -> CGRect { diff --git a/Sources/Layoutable.swift b/Sources/Layoutable.swift index d611180..8ed5a31 100644 --- a/Sources/Layoutable.swift +++ b/Sources/Layoutable.swift @@ -29,7 +29,7 @@ public protocol Layoutable: AnyObject, Equatable, CustomDebugStringConvertible { var superview: PinView? { get } var subviews: [PinView] { get } - var isVisible: Bool { get } + var isConsideredVisibleForViewFilters: Bool { get } func getRect(keepTransform: Bool) -> CGRect func setRect(_ rect: CGRect, keepTransform: Bool) diff --git a/Sources/PinLayout+WrapContent.swift b/Sources/PinLayout+WrapContent.swift index bf82a1f..c2b1621 100644 --- a/Sources/PinLayout+WrapContent.swift +++ b/Sources/PinLayout+WrapContent.swift @@ -31,7 +31,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(.all, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), viewFilter: viewFilter, { return "wrapContent()" }) } @@ -43,7 +43,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(padding: CGFloat, viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(.all, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), viewFilter: viewFilter, { return "wrapContent(padding: \(padding)" }) } @@ -58,7 +58,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(padding: PEdgeInsets, viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(.all, padding: padding, viewFilter: viewFilter, { return "wrapContent(padding: \(insetsDescription(padding))" }) } @@ -72,7 +72,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(_ type: WrapType, viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(_ type: WrapType, viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(type, padding: PEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), viewFilter: viewFilter, { return "wrapContent(\(type.description)" }) } @@ -88,7 +88,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(_ type: WrapType, padding: CGFloat, viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(_ type: WrapType, padding: CGFloat, viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(type, padding: PEdgeInsets(top: padding, left: padding, bottom: padding, right: padding), viewFilter: viewFilter, { return "wrapContent(\(type.description), padding: \(padding)" }) } @@ -104,7 +104,7 @@ extension PinLayout { - viewFilter: Specify whether to include all views or only visible ones. */ @discardableResult - public func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .none) -> PinLayout { + public func wrapContent(_ type: WrapType, padding: PEdgeInsets, viewFilter: ViewFilter = .all) -> PinLayout { return wrapContent(type, padding: padding, viewFilter: viewFilter, { return "wrapContent(\(type.description), padding: \(insetsDescription(padding))" }) } @@ -112,8 +112,8 @@ extension PinLayout { let subviews: [PinView.PinView] switch viewFilter { case .visibleOnly: - subviews = view.subviews.filter { $0.isVisible } - case .none: + subviews = view.subviews.filter { $0.isConsideredVisibleForViewFilters } + case .all: subviews = view.subviews } diff --git a/Sources/Types.swift b/Sources/Types.swift index c525202..2313456 100644 --- a/Sources/Types.swift +++ b/Sources/Types.swift @@ -195,8 +195,8 @@ public enum FitType { } @objc public enum ViewFilter: Int { - /// No filter, use all views - case none + /// Consider all views + case all /// Consider only visible views (isHidden is false and alpha is > 0) case visibleOnly } From de0868e562adbd009ef65a84db2ac0e544d6701f Mon Sep 17 00:00:00 2001 From: Ruslan Dzhafarov Date: Fri, 5 Apr 2024 20:31:20 +0300 Subject: [PATCH 09/10] update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a728f9d..712e9db 100644 --- a/README.md +++ b/README.md @@ -1371,12 +1371,12 @@ The following methods are useful to adjust view's width and/or height to wrap al **Methods:** -* **`wrapContent(viewFilter: ViewFilter = .none)`** -**`wrapContent(padding: CGFloat, viewFilter: ViewFilter = .none)`** -**`wrapContent(padding: UIEdgeInsets, viewFilter: ViewFilter = .none)`** +* **`wrapContent(viewFilter: ViewFilter = .all)`** +**`wrapContent(padding: CGFloat, viewFilter: ViewFilter = .all)`** +**`wrapContent(padding: UIEdgeInsets, viewFilter: ViewFilter = .all)`** Adjust the view's width and height to wrap all its subviews. The method also adjusts subviews's position to create a tight wrap. It is also possible to specify an optional padding around all subviews. Additionally, it's possible to specify whether to include all views or only visible ones. -* **`wrapContent(:WrapType, viewFilter: ViewFilter = .none)`** **`wrapContent(:WrapType, padding: UIEdgeInsets, viewFilter: ViewFilter = .none)`** -**`wrapContent(:WrapType, padding: CGFloat, viewFilter: ViewFilter = .none)`** +* **`wrapContent(:WrapType, viewFilter: ViewFilter = .all)`** **`wrapContent(:WrapType, padding: UIEdgeInsets, viewFilter: ViewFilter = .all)`** +**`wrapContent(:WrapType, padding: CGFloat, viewFilter: ViewFilter = .all)`** Adjust the view's width AND/OR height to wrap all its subviews. Accept a WrapType parameter to define the wrapping type. It is also possible to specify an optional padding around all subviews. Additionally, it's possible to specify whether to include all views or only visible ones. **Types:** @@ -1387,7 +1387,7 @@ Adjust the view's width AND/OR height to wrap all its subviews. Accept a WrapTyp * `.all`: Adjust the view's width AND height and update subviews position. This is the default WrapType parameter value `wrapContent()` methods. * **`ViewFilter`** values: - * `.none`: No filter, use all views + * `.all`: Consider all views * `.visibleOnly`: Consider only visible views (isHidden is false and alpha is > 0) ###### Usage examples: From 1bcd966decbb451bb810ee43e6f6d8f03c688532 Mon Sep 17 00:00:00 2001 From: Luc Dion Date: Tue, 17 Dec 2024 12:24:30 -0500 Subject: [PATCH 10/10] Update README.md Force rebuild --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 712e9db..df3b389 100644 --- a/README.md +++ b/README.md @@ -1961,3 +1961,4 @@ PinLayout recent history is available in the [CHANGELOG](CHANGELOG.md) also in [ ## License MIT License +