Skip to content

Commit

Permalink
API updates and method renames.
Browse files Browse the repository at this point in the history
  • Loading branch information
kreeger committed Feb 13, 2013
1 parent 4a4b40a commit 9b196da
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 24 deletions.
18 changes: 12 additions & 6 deletions BDKGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,48 @@
* @param size a new CGSize to assign to `rect`.
* @return a new rect with the given size.
*/
CGRect CGRectAdjustSize(CGRect rect, CGSize size);
CGRect CGRectSetSize(CGRect rect, CGSize size);
CGRect CGRectAdjustSize(CGRect rect, CGSize size) __attribute__((deprecated));

/** Gives a rect a new origin.
* @param rect the rect on which to operate.
* @param origin a new origin CGPoint to assign to `rect`.
* @return a new rect with the given origin.
*/
CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin);
CGRect CGRectSetOrigin(CGRect rect, CGPoint origin);
CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) __attribute__((deprecated));

/** Gives a rect's size a new width.
* @param rect the rect on which to operate.
* @param width a new width CGFloat to assign to `rect`.
* @return a new rect with the given width.
*/
CGRect CGRectAdjustWidth(CGRect rect, CGFloat width);
CGRect CGRectSetWidth(CGRect rect, CGFloat width);
CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) __attribute__((deprecated));

/** Gives a rect a new height.
* @param rect the rect on which to operate.
* @param size a new height CGFloat to assign to `rect`.
* @return a new rect with the given height.
*/
CGRect CGRectAdjustHeight(CGRect rect, CGFloat height);
CGRect CGRectSetHeight(CGRect rect, CGFloat height);
CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) __attribute__((deprecated));

/** Gives a rect a new y-origin.
* @param rect the rect on which to operate.
* @param size a new y-origin CGFloat to assign to `rect`.
* @return a new rect with the given y-origin.
*/
CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin);
CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin);
CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) __attribute__((deprecated));

/** Gives a rect a new x-origin.
* @param rect the rect on which to operate.
* @param size a new x-origin CGFloat to assign to `rect`.
* @return a new rect with the given x-origin.
*/
CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin);
CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin);
CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) __attribute__((deprecated));

/** Centers a child (sub) rect inside of a parent (master) rect, using both width and height.
* @param subRect the child rect, which will be altered and returned.
Expand Down
44 changes: 29 additions & 15 deletions BDKGeometry.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,79 @@
* Written by Ben Kreeger.
*/

CGRect CGRectAdjustSize(CGRect rect, CGSize size) {
CGRect CGRectSetSize(CGRect rect, CGSize size) {
rect.size = size;
return rect;
}

CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) {
CGRect CGRectAdjustSize(CGRect rect, CGSize size) { return CGRectSetSize(rect, size); }

CGRect CGRectSetOrigin(CGRect rect, CGPoint origin) {
rect.origin = origin;
return rect;
}

CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) {
CGRect CGRectAdjustOrigin(CGRect rect, CGPoint origin) { return CGRectSetOrigin(rect, origin); }

CGRect CGRectSetWidth(CGRect rect, CGFloat width) {
rect.size.width = width;
return rect;
}

CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) {
CGRect CGRectAdjustWidth(CGRect rect, CGFloat width) { return CGRectSetWidth(rect, width); }

CGRect CGRectSetHeight(CGRect rect, CGFloat height) {
rect.size.height = height;
return rect;
}

CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) {
CGRect CGRectAdjustHeight(CGRect rect, CGFloat height) { return CGRectSetHeight(rect, height); }

CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin) {
rect.origin.y = yOrigin;
return rect;
}

CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) {
CGRect CGRectAdjustYOrigin(CGRect rect, CGFloat yOrigin) { return CGRectSetYOrigin(rect, yOrigin); }

CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin) {
rect.origin.x = xOrigin;
return rect;
}

CGRect CGRectAdjustXOrigin(CGRect rect, CGFloat xOrigin) { return CGRectSetXOrigin(rect, xOrigin); }

CGRect CGRectCenterRectInRect(CGRect subRect, CGRect masterRect) {
CGPoint origin = CGPointMake((masterRect.size.width - subRect.size.width) / 2.0f,
(masterRect.size.height - subRect.size.height) / 2.0f);
return CGRectIntegral(CGRectAdjustOrigin(subRect, origin));
return CGRectIntegral(CGRectSetOrigin(subRect, origin));
}

CGRect CGRectCenterRectInRectHorizontally(CGRect subRect, CGRect masterRect) {
CGPoint origin = CGPointMake((masterRect.size.width - subRect.size.width) / 2.0f, subRect.origin.y);
return CGRectIntegral(CGRectAdjustOrigin(subRect, origin));
CGPoint origin = CGPointMake((CGRectGetWidth(masterRect) - CGRectGetWidth(subRect)) / 2.0f, subRect.origin.y);
return CGRectIntegral(CGRectSetOrigin(subRect, origin));
}

CGRect CGRectCenterRectInRectVertically(CGRect subRect, CGRect masterRect) {
CGPoint origin = CGPointMake(subRect.origin.x, (masterRect.size.height - subRect.size.height) / 2.0f);
return CGRectIntegral(CGRectAdjustOrigin(subRect, origin));
CGPoint origin = CGPointMake(subRect.origin.x, (CGRectGetHeight(masterRect) - CGRectGetHeight(subRect)) / 2.0f);
return CGRectIntegral(CGRectSetOrigin(subRect, origin));
}

CGRect CGRectInsetByPercent(CGRect rect, CGFloat xPercent, CGFloat yPercent) {
return CGRectIntegral(CGRectInset(rect, rect.size.width * xPercent, rect.size.height * yPercent));
CGRect oldRect = rect;
rect = CGRectSetSize(rect, CGSizeMake(rect.size.width * xPercent, rect.size.height * yPercent));
return CGRectCenterRectInRect(rect, oldRect);
}

void CGRectIntegralSizeToFit(UIView *view) {
[view sizeToFit];
[view sizeToFit];
view.frame = CGRectIntegral(view.frame);
}

CGSize CGSizeByDoubling(CGSize size) {
return CGSizeMake(size.width * 2.0f, size.height * 2.0f);
return CGSizeMake(size.width * 2.0f, size.height * 2.0f);
}

CGRect CGRectByDoublingSize(CGRect rect) {
return CGRectAdjustSize(rect, CGSizeByDoubling(rect.size));
return CGRectSetSize(rect, CGSizeByDoubling(rect.size));
}
4 changes: 2 additions & 2 deletions BDKGeometry.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BDKGeometry'
s.version = '1.0.1'
s.version = '1.1.0'
s.platform = :ios
s.summary = "A set of helper functions I've been using in various XCode projects, abstracted for great good."
s.homepage = 'http://github.com/kreeger/BDKGeometry'
Expand All @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
LICENSE
}
s.author = { 'Ben Kreeger' => 'ben@kree.gr' }
s.source = { :git => 'https://github.com/kreeger/BDKGeometry.git', :tag => 'v1.0.1' }
s.source = { :git => 'https://github.com/kreeger/BDKGeometry.git', :tag => 'v1.1.0' }
s.ios.deployment_target = '5.0'
s.source_files = 'BDKGeometry.{h,m}'
s.requires_arc = true
Expand Down
35 changes: 34 additions & 1 deletion readme.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# BDKGeometry

A set of helper functions I've been using in various XCode projects, abstracted for great good! Documentation coming soon.
A set of helper functions I've been using in various XCode projects, abstracted for great good!

## Getting started

Really all you should do is check out [the header file][0], but here's a list of the methods available.

``` objective-c
CGRect CGRectSetSize(CGRect rect, CGSize size);
CGRect CGRectSetOrigin(CGRect rect, CGPoint origin);
CGRect CGRectSetWidth(CGRect rect, CGFloat width);
CGRect CGRectSetHeight(CGRect rect, CGFloat height);
CGRect CGRectSetYOrigin(CGRect rect, CGFloat yOrigin);
CGRect CGRectSetXOrigin(CGRect rect, CGFloat xOrigin);
CGRect CGRectCenterRectInRect(CGRect subRect, CGRect masterRect);
CGRect CGRectCenterRectInRectHorizontally(CGRect subRect, CGRect masterRect);
CGRect CGRectCenterRectInRectVertically(CGRect subRect, CGRect masterRect);
CGRect CGRectInsetByPercent(CGRect rect, CGFloat xPercent, CGFloat yPercent);
void CGRectIntegralSizeToFit(UIView *view);
CGSize CGSizeByDoubling(CGSize size);
CGRect CGRectByDoublingSize(CGRect rect);
```
## Installation
Use [CocoaPods][1], you dingus!
``` ruby
# Podfile
platform :ios, '5.0'
pod 'BDKGeometry', '~> 1.1.0'
```

[0]: https://github.com/kreeger/BDKGeometry/blob/master/BDKGeometry.h

0 comments on commit 9b196da

Please sign in to comment.