README.md in motion-kit-0.9.6 vs README.md in motion-kit-0.10.0

- old
+ new

@@ -9,31 +9,30 @@ - [ApplicationKit][readmore-applicationkit] - [AutoLayout][readmore-autolayout] - [Frame geometry][readmore-frames] - [CoreAnimation][readmore-coreanimation] - [NSMenu/NSMenuItem][readmore-nsmenu] - - [Joybox][readmore-joybox] *TODO* - - [SpriteKit][readmore-spritekit] *TODO* -4. Non-polluting -5. ProMotion/RMQ/SugarCube-compatible (kind of goes hand-in-hand with non-polluting) -6. Styles and layouts are "just code" (not hash-based like in Teacup) -7. Written by [the authors][authors] of [ProMotion][] and [Teacup][] +4. Easily extendable to support custom, mini-DSLs +5. Non-polluting +6. ProMotion/RMQ/SugarCube-compatible (kind of goes hand-in-hand with being non-polluting) +7. Styles and layouts are "just code" (not hash-based like in Teacup) +8. Written by [the authors][authors] of [ProMotion][] and [Teacup][] [authors]: CONTRIBUTORS.md [Colin]: https://github.com/colinta [Jamon]: https://github.com/jamonholmgren [ProMotion]: https://github.com/clearsightstudio/ProMotion [RMQ]: https://github.com/infinitered/rmq [Teacup]: https://github.com/rubymotion/teacup +[SweetKit]: https://github.com/rubymotion/sweet-kit +[READMORE]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md [readmore-uikit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#uikit [readmore-applicationkit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#applicationkit -[readmore-joybox]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#joybox -[readmore-spritekit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#spritekit [readmore-coreanimation]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#coreanimation -[readmore-frames]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#frames -[readmore-autolayout]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#autolayout +[readmore-frames]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#frames +[readmore-autolayout]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#autolayout [readmore-nsmenu]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#nsmenu ## What happened to Teacup?? @@ -368,11 +367,21 @@ end end ``` +### Even more information... +...is in the [READMORE][] document. I re-explain some of these topics, go into +some more detail, that kinda thing. Basically an overflow document for topics I +don't want to stuff into the README. + + +## MotionKit extensions + +These are all built-in, unless otherwise specified. + ### Frames There are lots of frame helpers for NSView and UIView subclasses. It's cool that you can set position and sizes as percents, but scroll down to see examples of setting frames *based on any other view*. These are super useful! Most of @@ -639,15 +648,26 @@ end end ``` +### MotionKit::Events -### Some handy tricks and Features + gem install motion-kit-events -#### Orientation specific styles +Adds `on :event` and `trigger :event` methods to `MK::Layout` objects. These +can be used to send events from the Layout to your controller, further +simplifying the controller code (and usually making it more testable). See the +[MotionKit::Events documentation][motion-kit-events] for more information. +[motion-kit-events]: https://github.com/rubymotion/motion-kit-events + + +## Some handy tricks and Features + +### Orientation specific styles + These are available on iOS. ```ruby add UIView, :container do portrait do @@ -657,11 +677,11 @@ frame from_top_left(width: 300, height: 100) end end ``` -#### Update views via 'initial', 'reapply', and 'deferred' +### Update views via 'initial', 'reapply', and 'deferred' If you call 'layout.reapply!', your style methods will be called again (but NOT the `layout` method). You very well might want to control what methods get called on later invocations, or only on the *initial* layout. @@ -696,11 +716,11 @@ end end ``` -#### Apply styles via module +### Apply styles via module ```ruby module AppStyles def rounded_button @@ -725,13 +745,30 @@ end end ``` +### Using SweetKit -#### Setting a custom root view +The [SweetKit][] gem combines MotionKit and SugarCube. The helpers it provides +allow for even more expressiveness, for instance: +```ruby +add UITextField do + return_key_type :email + text_alignment :right +end +``` + +The OS X helpers are really nice, because it tries to hide most of the +annoying subtletees of the NSCell/NSControl dichotomy. + + gem install sweet-kit + + +### Setting a custom root view + If you need to use a custom root view, you can use the `root` method from within the `layout` method. When you create or assign the root view this way, you must assign subviews and styles *inside* a block that you pass to `root`. ```ruby @@ -740,9 +777,32 @@ add UILabel end end ``` +You can also pass in a root view to your layout, like this: + +```ruby +def loadView + @layout = MyLayout.new(root: self.view) +end +``` + +In this case, if you want to style the root view, just refer to it in your layout: + +```ruby +def layout + root :my_root_view do + # ... + end +end + +def my_root_view_style + background_color UIColor.grayColor +end +``` + +This is especially useful with collection views, table views, and table cells. # Contributing We welcome your contributions! Please be sure to run the specs before you do, and consider adding support for both iOS and OS X.