-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrap content calculation by filter hidden views #280
base: master
Are you sure you want to change the base?
Changes from 4 commits
e20a081
98258f8
fb3a375
7d756bc
6d81204
69903d5
46e93fa
44697d4
de0868e
1bcd966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,21 +26,25 @@ 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() -> 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()" }) | ||||
} | ||||
|
||||
/** | ||||
Adjust the view's width & height to wrap all its subviews. The method also adds a padding around all subviews. | ||||
|
||||
- Parameters: | ||||
- padding: Specify a padding value. | ||||
- viewFilter: Specify whether to include all views or only visible ones. | ||||
*/ | ||||
@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)" }) | ||||
} | ||||
|
||||
/** | ||||
|
@@ -51,10 +55,11 @@ 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) -> 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))" }) | ||||
} | ||||
|
||||
/** | ||||
|
@@ -64,10 +69,11 @@ 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) -> 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)" }) | ||||
} | ||||
|
||||
/** | ||||
|
@@ -79,10 +85,11 @@ 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) -> 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)" }) | ||||
} | ||||
|
||||
/** | ||||
|
@@ -94,14 +101,22 @@ 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) -> 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 | ||||
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 } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about views with There is public PinLayout/Sources/Filters.swift Line 25 in babea9c
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, you could use the |
||||
case .none: | ||||
subviews = view.subviews | ||||
} | ||||
|
||||
guard !subviews.isEmpty else { return self } | ||||
|
||||
let firstViewRect = subviews[0].getRect(keepTransform: keepTransform) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need default argument value (
viewFilter = .none
) in private function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed here, the parameter should always be specified by callers