Skip to content

Commit

Permalink
updated README and package updates
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Dec 12, 2014
1 parent 14af3ac commit f9a0dd4
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
sugarcube (3.0.1)
sugarcube (3.0.2)

GEM
remote: https://rubygems.org/
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ the packages you need:
###### Gemfile
```ruby
gem 'sugarcube', :require => [
'sugarcube-uikit',
'sugarcube-ui',
'sugarcube-events',
'sugarcube-gestures',
'sugarcube-568',
Expand All @@ -103,7 +103,7 @@ require 'motion/project/template/ios'
require 'bundler'
Bundler.require

require 'sugarcube-uikit'
require 'sugarcube-ui'
require 'sugarcube-events'
require 'sugarcube-gestures'
require 'sugarcube-568'
Expand Down Expand Up @@ -192,26 +192,44 @@ Be sure to read more in the [REPL Additions][REPL Wiki] Wiki page.

[REPL Wiki]: https://github.com/rubymotion/sugarcube/wiki/REPL-Additions

UIKit ([wiki][UIKit Wiki])
UI on iOS: UIKit extensions ([wiki][UIKit Wiki])
-----

A big package chock full of methods to make working in UIKit a joy.

> `require 'sugarcube-uikit'`
> `require 'sugarcube-ui'`
A few varieties of methods are in this package:

* Conversions: `'string-to'.uiimage`, `image.uiimageview`
* Conversions: `'string-to'.uiimage`, `image.uiimageview`, `'string-to'.uilabel(font)`
* Helpers: shorthands for common operations, like `a_view << a_subview`, `a_subview.convert_frame_to(a_view)`
* Symbols: `:system.uifont(20)`, `:label.uifontsize`
* Frame accessors: `a_view.x`, `a_view.x = 100`
* Frame accessors: `a_view.x`, `a_view.x = 100` (on `UIView` and `CALayer`)

There are too many methods to define here. Instead: a complete list of methods
is available in the [documentation][], and the [wiki page][UIKit Wiki] is a
great source as well.

[UIKit Wiki]: https://github.com/rubymotion/sugarcube/wiki/UIKit

UI on OS X: AppKit extensions
-----

Similar extensions as the iOS version, but using the `ns` prefix on method names:

* Conversions: `'string-to'.nsimage`, `image.nsimageview`, `'string-to'.nslabel(font)`
* Helpers: `view << subview`
* Symbols: `:white.nscolor`, `:system.nsfont`
* Frame accessors: `a_view.x`, `a_view.x = 100` (on `UIView`, `CALayer`, `NSWindow`, and `NSScreen`)

UI on Android
-----

*(warning: extending built-in classes is not reliable in RubyMotion on Android)*

ViewGroup gets the same `<<` method that you see in UIView and NSView.


Constants
-----

Expand Down Expand Up @@ -1256,7 +1274,7 @@ issues with missing constants).
```

And you can easily turn an attributed string into a label, if you include the
`sugarcube-uikit` package.
`sugarcube-ui` package.

```ruby
view << (("We just met\n".attrd +
Expand Down
44 changes: 44 additions & 0 deletions lib/osx/sugarcube-ui/frameable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,47 @@ class CALayer
class NSScreen
include SugarCube::Frameable
end

class NSWindow

def x
self.frame.origin.x
end

def setX(newX)
new_frame = self.frame
new_frame.origin.x = newX
self.setFrame(new_frame, display: false)
end

def y
self.frame.origin.y
end

def setY(newY)
new_frame = self.frame
new_frame.origin.y = newY
self.setFrame(new_frame, display: false)
end

def height
self.frame.size.height
end

def setHeight(newHeight)
new_frame = self.frame
new_frame.size.height = newHeight
self.setFrame(new_frame, display: false)
end

def width
self.frame.size.width
end

def setWidth(newWidth)
new_frame = self.frame
new_frame.size.width = newWidth
self.setFrame(new_frame, display: false)
end

end
6 changes: 2 additions & 4 deletions lib/sugarcube-classic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
'sugarcube-common.rb',
'sugarcube-classic.rb',
'sugarcube-legacy.rb',
'sugarcube-uicolor.rb',
'sugarcube-uiimage.rb',
'sugarcube-spritekit.rb',

'sugarcube-568.rb',
Expand All @@ -17,16 +15,16 @@
'sugarcube-pipes.rb',
'sugarcube-repl.rb',
'sugarcube-unholy.rb',
'sugarcube-appkit.rb',
'sugarcube-uikit.rb',
]

if SugarCube.ios?
exclude += [
'sugarcube-appkit.rb',
]
elsif SugarCube.osx?
exclude += [
'sugarcube-modal.rb',
'sugarcube-uikit.rb',
]
end

Expand Down
6 changes: 2 additions & 4 deletions lib/sugarcube-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
'sugarcube-common.rb',
'sugarcube-classic.rb',
'sugarcube-legacy.rb',
'sugarcube-uicolor.rb',
'sugarcube-uiimage.rb',

'sugarcube-anonymous.rb',
'sugarcube-awesome.rb',
'sugarcube-pipes.rb',
'sugarcube-unholy.rb',
'sugarcube-appkit.rb',
'sugarcube-uikit.rb',
]

if SugarCube.ios?
exclude += [
'sugarcube-appkit.rb',
]
elsif SugarCube.osx?
exclude += [
'sugarcube-568.rb',
'sugarcube-gestures.rb',
'sugarcube-modal.rb',
'sugarcube-uikit.rb',
]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SugarCube
Version = '3.0.1'
Version = '3.0.2'
end
178 changes: 178 additions & 0 deletions spec/osx/frameable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
describe SugarCube::Frameable do

describe NSView do

it 'should return x' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.x.should == view.frame.origin.x
end

it 'should set x' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.x = 500
view.x.should == 500
end

it 'should return y' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.y.should == view.frame.origin.y
end

it 'should set y' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.y = 500
view.y.should == 500
end

it 'should return width' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.width.should == view.frame.size.width
end

it 'should set width' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.width = 500
view.width.should == 500
end

it 'should return height' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.height.should == view.frame.size.height
end

it 'should set height' do
view = NSView.alloc.initWithFrame([[100, 200], [300, 400]])
view.height = 500
view.height.should == 500
end

end

describe CALayer do

it 'should return x' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.x.should == layer.frame.origin.x
end

it 'should set x' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.x = 500
layer.x.should == 500
end

it 'should return y' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.y.should == layer.frame.origin.y
end

it 'should set y' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.y = 500
layer.y.should == 500
end

it 'should return width' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.width.should == layer.frame.size.width
end

it 'should set width' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.width = 500
layer.width.should == 500
end

it 'should return height' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.height.should == layer.frame.size.height
end

it 'should set height' do
layer = CALayer.layer
layer.frame = [[100, 200], [300, 400]]
layer.height = 500
layer.height.should == 500
end

end

describe NSWindow do

before do
@window = NSWindow.alloc.initWithContentRect([[240, 180], [480, 360]],
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
backing: NSBackingStoreBuffered,
defer: false)
end

it 'should return x' do
@window.x.should == @window.frame.origin.x
end

it 'should set x' do
@window.x = 500
@window.x.should == 500
end

it 'should return y' do
@window.y.should == @window.frame.origin.y
end

it 'should set y' do
@window.y = 500
@window.y.should == 500
end

it 'should return width' do
@window.width.should == @window.frame.size.width
end

it 'should set width' do
@window.width = 500
@window.width.should == 500
end

it 'should return height' do
@window.height.should == @window.frame.size.height
end

it 'should set height' do
@window.height = 500
@window.height.should == 500
end

end

describe NSScreen do

it 'should return x' do
view = NSScreen.alloc.initWithFrame([[100, 200], [300, 400]])
view.x.should == view.frame.origin.x
end

it 'should return y' do
view = NSScreen.alloc.initWithFrame([[100, 200], [300, 400]])
view.y.should == view.frame.origin.y
end

it 'should return width' do
view = NSScreen.alloc.initWithFrame([[100, 200], [300, 400]])
view.width.should == view.frame.size.width
end

it 'should return height' do
view = NSScreen.alloc.initWithFrame([[100, 200], [300, 400]])
view.height.should == view.frame.size.height
end

end

end

0 comments on commit f9a0dd4

Please sign in to comment.