From f5f15f94d36d49aecfab86af47181018e80ee7b0 Mon Sep 17 00:00:00 2001 From: eonist <30n1st@gmail.com> Date: Thu, 29 Jun 2023 21:47:35 +0200 Subject: [PATCH] Add warning if sizeOffset is set when it should not --- Sources/Spatial/view/View+Access.swift | 3 ++- Sources/Spatial/view/View+Size.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Spatial/view/View+Access.swift b/Sources/Spatial/view/View+Access.swift index bea3eb1..38f6bc2 100644 --- a/Sources/Spatial/view/View+Access.swift +++ b/Sources/Spatial/view/View+Access.swift @@ -24,9 +24,10 @@ extension View { */ public func anchorAndSize(to: View, sizeTo: View? = nil, width: CGFloat? = nil, height: CGFloat? = nil, align: Alignment = .topLeft, alignTo: Alignment = .topLeft, multiplier: CGSize = .init(width: 1, height: 1), offset: CGPoint = .zero, sizeOffset: CGSize = .zero, useMargin: Bool = false) { self.activateAnchorAndSize { _ in - let anchor = Constraint.anchor(self, to: to, align: align, alignTo: alignTo, offset: offset, useMargin: useMargin) + let anchor: AnchorConstraint = Constraint.anchor(self, to: to, align: align, alignTo: alignTo, offset: offset, useMargin: useMargin) let size: SizeConstraint = { if let width = width, let height = height { // This method exists when you have size, but don't want to set size based on another view + if sizeOffset != .zero { Swift.print("⚠️️ sizeOffset does not affect constraints when width and height are predfined, set offset to the width and height directly") } return Constraint.size(self, size: .init(width: width, height: height), multiplier: multiplier) } else { return Constraint.size(self, to: sizeTo ?? to, width: width, height: height, offset: sizeOffset, multiplier: multiplier) diff --git a/Sources/Spatial/view/View+Size.swift b/Sources/Spatial/view/View+Size.swift index 4fabd09..8c2ee0b 100644 --- a/Sources/Spatial/view/View+Size.swift +++ b/Sources/Spatial/view/View+Size.swift @@ -34,7 +34,7 @@ extension Constraint { } /** * Creates a size constraint - * - Fixme: ⚠️️ This doesn't have offset, maybe it should, for now I guess you can always inset the size + * - Fixme: ⚠️️ This doesn't have offset, maybe it should, for now I guess you can always inset the size, or add etc * ## Examples: * let sizeConstraint = Constraint.size(square, size: .init(width: 100, height: 100)) * - Parameters: