lib/geomotion/cg_rect.rb in geomotion-0.13.2 vs lib/geomotion/cg_rect.rb in geomotion-0.14.0
- old
+ new
@@ -310,41 +310,46 @@
end
# adjacent rects
def above(margin = 0, options={})
margin, options = 0, margin if margin.is_a?(NSDictionary)
+ margin = options.delete(:margin) if options.key?(:margin)
height = options[:height] || self.size.height
self.apply({
up: height + margin
}.merge(options))
end
def below(margin = 0, options={})
margin, options = 0, margin if margin.is_a?(NSDictionary)
+ margin = options.delete(:margin) if options.key?(:margin)
self.apply({
down: self.size.height + margin
}.merge(options))
end
def before(margin = 0, options={})
margin, options = 0, margin if margin.is_a?(NSDictionary)
+ margin = options.delete(:margin) if options.key?(:margin)
width = options[:width] || self.size.width
self.apply({
left: width + margin
}.merge(options))
end
def beside(margin = 0, options={})
margin, options = 0, margin if margin.is_a?(NSDictionary)
+ margin = options.delete(:margin) if options.key?(:margin)
self.apply({
right: self.size.width + margin
}.merge(options))
end
+ alias after beside
# these methods create a rect INSIDE the receiver
# Create a rect inside the receiver, on the left side. If `margin` is
# supplied, the rect will be moved that number of points to the right.
@@ -414,10 +419,14 @@
else
CGPoint.new(0, 0)
end
end
+ def to_ary
+ [self.origin, self.size]
+ end
+
public
def center(absolute = false)
cgrect_offset(absolute) + CGPoint.new(self.size.width / 2, self.size.height / 2)
end
@@ -527,19 +536,21 @@
end
return rect
end
alias grow_right wider
+
def grow_left(amount, options={})
raise "You must specify an amount in `CGRect#grow_left`" unless amount.is_a?(Numeric)
self.apply({
grow_left: amount
}.merge(options))
end
alias grow_down taller
+
def grow_up(amount, options={})
raise "You must specify an amount in `CGRect#grow_up`" unless amount.is_a?(Numeric)
self.apply({
grow_up: amount
@@ -564,18 +575,20 @@
end
return rect
end
alias shrink_left thinner
+
def shrink_right(amount, options={})
raise "You must specify an amount in `CGRect#shrink_right`" unless amount.is_a?(Numeric)
self.apply({
shrink_right: amount
}.merge(options))
end
alias shrink_up shorter
+
def shrink_down(amount, options={})
raise "You must specify an amount in `CGRect#shrink_down`" unless amount.is_a?(Numeric)
self.apply({
shrink_down: amount