sugarcube v0.6

UIAlertView added in v0.5

I didn’t announce v0.5. It added UIAlertView.alert. If you blatantly disregard Apple’s recommendation NOT to subclass UIAlertView, you can still use this method to show your alert! So that’s fun.

“`ruby

simple - just a success handler

UIAlertView.alert "This is happening, OK?” { self.happened! }

a little more complex; more buttons, a title, a message, and a success handler

UIAlertView.alert(“This is happening, OK?”, buttons: [“Nevermind”, “OK”], message: “don’t worry, it’ll be fine.”) { self.happened! }

Full on whiz bangery. Note the success block takes the pressed button, but as

a string instead of an index. The cancel button should be the first entry in

buttons:

UIAlertView.alert “I mean, is this cool?”, buttons: %w[No! Sure! Hmmmm] message: “No going back now”, cancel: { self.cancel }, success: { |pressed| self.proceed if pressed == “Sure!” } “`

CoreGraphics extensions has been overhauled!

If you were using the classes CGRectArray directly, you will need to update your code.

I hadn’t realized that you can have a method called Rect and a class called Rect, and all is well! So I did that. CGRectArray is now just SugarCube::CoreGraphics::Rect. If you are going to use the CoreGraphics extensions, you should include SugarCube::CoreGraphics at the top of app_delegate.rb.

These have been rewritten to make use of the CGGeometry methods like CGRectMaxX and CGRectIntersectsRect. The methods I’ve added are written as a module (SugarCube::CGRectExtensions, SugarCube::CGSizeExtensions, SugarCube::CGPointExtensions) and added to CGRect and Rect. Did you know you can even extend CGRect!? It’s almost as if everything is an object! Crazy.

”`ruby view.frame.left # => CGRectMinX(view.frame) (NOT the same as view.frame.origin.x) view.frame.center view.frame += Size(10, 10) # => CGRectInset(self, -10, -10) - e.g. BIGGER by 10x/10px view.frame += Size(-10, -10) # => CGRectInset(self, 10, 10) - e.g. SMALLER by 10x/10px view.frame += EdgeInsets(1, 2, 3, 4) # => UIEdgeInsetsInsetRect(self, UIMakeEdgeInsets(1, 2, 3, 4))

=> smaller by 1px on top, 2 on the left, 3 on the bottom, and 4 on the right

“`

You can add most things. Point + Size = Rect, Rect + Point = Offset rect by point. But one that might throw you is the Rect + Size = CGRectInset. Adding a size does increase the size of the Rect, but it retains its center. It expands equally in all directions.

A few methods added: CGRect#intersection, CGRect#intersects?, CGRect#contains?

ruby view.frame.intersects? another_frame view.frame.intersects? point # contains? is an alias for this view.frame.contains? another_frame # another_frame must be completey consumed by view.frame

And there are factory methods

”`ruby Rect.null # => CGRectNull Rect.null.null? # => true. all other rects => false

Rect.empty # => [[0, 0], [0, 0]] Rect.empty.empty? # => true. any rect with zero width or height is “empty”

Rect.infinite # => [[0, 0], [Infinity, Infinity]] Rect.infinite.infinite? # => true. The CGRectIsInfinite method returns false, though. “`

The CGRectIsInfinite bug is intractable. Try it yourself - open a REPL and type CGRectIsInfinite(CGRectInfinite). You should get "1”, but I get “0”. So even the built in CGRectInfinite constant doesn’t work. sugarcube, instead, checks for a size of infinite extent.

“`ruby Size.infinite # => [Infinity, Infinity] Size.infinite.infinite? # => true

Rect(123, 456, 1/0, 1/0).infinite? # => true ”`

to_s everywhere!

My goal for v0.7 is to have lots of to_s methods. I’ve added some for UIEvent, UITouch, NSSet, and others. If I miss something, please send a pull request. I’m just adding these because they help during development.

to_s methods for many of the UIView classes is still in the cards as well. This will make the SugarCube::Adjust::tree command that much more useful.

keep on keepin' on!