[swift-evolution] Proposal: Extend CG(Rect)Geometry with center methods

Dave Abrahams dabrahams at apple.com
Mon Dec 14 00:33:39 CST 2015


> On Dec 10, 2015, at 6:17 AM, D. Felipe Torres via swift-evolution <swift-evolution at swift.org> wrote:
> 
> One of the task that is performed often is center a frame with respect to it's parent.
> The code for this is short and simple:
> 
> rect.origin.x = (rect.width-parent.width)/2 // or... 
> rect.origin.y = (rect.height-parent.height)/2
> 
> ## Current Problems
> 
> - It is very easy to get it wrong and confuse X or Y and their length associations.
> - Because this code is often found in a layout method, several other rect variables may be defined in the scope which makes it easier to mistake one variable with another if their names are close (and you are used to autocomplete)
> - And finally but most importantly, while the equation here is simple, one must parse it and understand it and is not a very swifty approach.
> 
> ##Proposed Additions 
> 
> 2 (actually 4) extensions in CGGeometry to CGRect:
> 
> extension CGRect {
>       public func centerX(parentRect: CGRect) -> CGRect
>       public mutating func centerXInPlace(parentRect: CGRect)
>       public fun centerY(parentRect: CGRect) -> CGRect
>       public mutating func centerYInPlace(parentRect: CGRect)
> }
> 
> This extension allows very easily (and verbally) center a rect in respect to a parent.
> 
> I'm pretty sure there are other pretty useful extensions that can be added to CGGeometry as well but this one I think is basic and pretty important.
> 
> -- 
> ++++++++++++++++++++++++++
> Diego Torres.
> Web: dtorres.me <http://dtorres.me/> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


Hi Diego,

Although the framework overlays (https://github.com/apple/swift/tree/master/stdlib/public/SDK <https://github.com/apple/swift/tree/master/stdlib/public/SDK>) are currently in the Swift repository, the Swift project doesn't own these APIs; they belong to the respective framework owners.  Changes to the Swift APIs of the framework, therefore, need to be proposed to the framework owners.  I would do that through bugreport.apple.com <http://bugreport.apple.com/> using component "CoreGraphics / X".

HTH,
Dave



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/4bdfe3eb/attachment.html>


More information about the swift-evolution mailing list