purplish-frame 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1753bb78dcbd8c89effa4f8f3fbd8e2a9ac54229
4
- data.tar.gz: e52c3215df642821bc6ae41393b20466387fdd5b
3
+ metadata.gz: 620ee6f6ae016e428618a81f1d44ba6d8f72985b
4
+ data.tar.gz: 759de6822bda48e2b1a0eea47ad4534fd563168d
5
5
  SHA512:
6
- metadata.gz: d1fe0c25fbd1cce1cdb6ab3946c3d845ffce25903568879e01c74b2263aad557c8ba07ded7a2272cdfa176759a361583b7c193a6e7ef622ef8cfb7755d554d8b
7
- data.tar.gz: 4bd721f95fe0a4c1e191311f2b4519cb018ee8a483e2a6c250c37acb46d34ebc4b2a59ec9327ad0a2798f1b8c6d8d19dd119ef6ef324a2aefd411190868a28a4
6
+ metadata.gz: 5761348b7fec5d0dc1635b876b1379cb4971a178a530ea724930feb85be558d8ce0afca47ac39526961a289089e196c79c72cfdbc3978b63d87d3c012e5aaf7d
7
+ data.tar.gz: 86a7b65265ceee3365c406d970d65e07ef52163d800261416325d8dfdef7613fd8c788a25fce8cc6ecf4d59e4fac8be883d8f489407c218b8d74bfd90311c6f8
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ build/
4
4
  .DS_Store
5
5
  .repl_history
6
6
  0
7
+ Gemfile.lock
data/README.md CHANGED
@@ -5,45 +5,52 @@ Usage
5
5
  For iOS & OS X:
6
6
 
7
7
  ```ruby
8
- rect = CGRect.new(10, -20, 100, 100)
8
+ rect = CGRectMake(10, -20, 100, 100)
9
9
  rect.left
10
- #10
10
+ => #10
11
11
  rect.right
12
- #110
12
+ => #110
13
13
  rect.top
14
- #-20
14
+ => #-20
15
15
  rect.bottom
16
- #80
16
+ => #80
17
17
  rect.width
18
- #100
18
+ => #100
19
19
  rect.height
20
- #100
20
+ => #100
21
21
  rect.center_x
22
- #60
22
+ => #60
23
23
  rect.center_y
24
- #30
24
+ => #30
25
25
  ```
26
26
 
27
27
  Similar usage for UIView for iOS and NSView, NSSize, NSPoint, NSRect for OS X.
28
28
 
29
+ ```ruby
30
+ rect = CGRectMake(10, -20, 100, 100)
31
+ rect.inset(5, 20)
32
+ => #<CGRect origin=#<CGPoint x=15.0 y=0.0> size=#<CGSize width=90.0 height=60.0>>
33
+ ```
34
+ Similar usage for UIView for iOS and NSView, NSRect for OS X.
35
+
29
36
  ```ruby
30
37
  CGSize.new(100, 100).scale_to_fit(CGSize.new(10, 10))
31
- #CGSize.new(10, 10)
38
+ => #<CGSize width=10.0 height=10>
32
39
 
33
40
  CGSize.new(200, 100).scale_to_fill(CGSize.new(15, 15))
34
- #CGSize.new(30, 15)
41
+ => #<CGSize width=30 height=15>
35
42
 
36
43
  CGSize.new(100, 100).scale_to_fit!
37
44
  CGSize.new(200, 100).scale_to_fill!
38
45
 
39
46
  CGPoint.new(100, 200)*10
40
- #CGPoint.new(1000, 2000)
47
+ => #<CGPoint x=1000 y=2000>
41
48
 
42
49
  CGPoint.new(100, 200)/10
43
- #CGPoint.new(10, 20)
50
+ => #<CGPoint x=10 y=20>
44
51
 
45
- CGRect.new(10, 20, 100, 100).scale(10)
46
- #CGRect.new(100, 200, 1000, 1000)
52
+ CGRectMake(10, 20, 100, 100).scale(10)
53
+ => #<CGRect origin=#<CGPoint x=100.0 y=200.0> size=#<CGSize width=1000.0 height=1000.0>>
47
54
  ```
48
55
 
49
56
  Similar usage for NSSize, NSPoint, NSRect on OS X.
@@ -28,4 +28,8 @@ class CGRect
28
28
  def height=(h)
29
29
  size.height = h
30
30
  end
31
+
32
+ def inset(dx, dy)
33
+ CGRectInset(self, dx, dy)
34
+ end
31
35
  end
@@ -28,4 +28,8 @@ class NSRect
28
28
  def height=(h)
29
29
  size.height = h
30
30
  end
31
+
32
+ def inset(dx, dy)
33
+ NSInsetRect(self, dx, dy)
34
+ end
31
35
  end
@@ -95,5 +95,9 @@ module PurplishFrame
95
95
  size_height_to_fit
96
96
  self.height = f if height < f
97
97
  end
98
+
99
+ def inset!(dx, dy)
100
+ self.frame = frame.inset(dx, dy)
101
+ end
98
102
  end
99
103
  end
@@ -1,3 +1,3 @@
1
1
  module PurplishFrame
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -28,4 +28,10 @@ describe "Rects" do
28
28
  rect.center_y.should.equal 30
29
29
  end
30
30
 
31
+ it "Insets" do
32
+ rect = CGRectMake(10, -20, 100, 100)
33
+ rect.inset(10, 10).should.close CGRectMake(20, -10, 80, 80), delta
34
+ rect.inset(5, 20).should.close CGRectMake(15, 0, 90, 60), delta
35
+ rect.inset(-5, -20).should.close CGRectMake(5, -40, 110, 140), delta
36
+ end
31
37
  end
@@ -6,6 +6,8 @@ end
6
6
 
7
7
  if PurplishFrame.osx?
8
8
  describe "Rects" do
9
+ delta = 0.0001
10
+
9
11
  it "NSRect sides" do
10
12
  #Careful not to use NSMakeRect(). Somehow, it creates a CGRect instead
11
13
  rect = NSRect.new([10, -20], [100, 100])
@@ -18,5 +20,13 @@ if PurplishFrame.osx?
18
20
  rect.center_x.should.equal 60
19
21
  rect.center_y.should.equal 30
20
22
  end
23
+
24
+ it "Insets" do
25
+ #Careful not to use NSMakeRect(). Somehow, it creates a CGRect instead
26
+ rect = NSRect.new([10, -20], [100, 100])
27
+ rect.inset(10, 10).should.close NSRect.new([20, -10], [80, 80]), delta
28
+ rect.inset(5, 20).should.close NSRect.new([15, 0], [90, 60]), delta
29
+ rect.inset(-5, -20).should.close NSRect.new([5, -40], [110, 140]), delta
30
+ end
21
31
  end
22
32
  end
@@ -1,15 +1,40 @@
1
1
  if PurplishFrame.ios?
2
+ class CGRect
3
+ def close?(to, delta)
4
+ origin.x.close?(to.origin.x, delta) && origin.y.close?(to.origin.y, delta) && size.width.close?(to.size.width, delta) && size.height.close?(to.size.height, delta)
5
+ end
6
+ end
7
+
2
8
  describe "UIView" do
9
+ delta = 0.0001
10
+ before do
11
+ @v = UIView.alloc.initWithFrame([[10, 20], [100, 200]])
12
+ end
13
+
3
14
  it "Accessing" do
4
- v = UIView.alloc.initWithFrame([[10, 20], [100, 200]])
5
- v.left.should.equal 10
6
- v.right.should.equal 110
7
- v.top.should.equal 20
8
- v.bottom.should.equal 220
9
- v.center_x.should.equal 60
10
- v.center_y.should.equal 120
11
- v.width.should.equal 100
12
- v.height.should.equal 200
15
+ @v.left.should.equal 10
16
+ @v.right.should.equal 110
17
+ @v.top.should.equal 20
18
+ @v.bottom.should.equal 220
19
+ @v.center_x.should.equal 60
20
+ @v.center_y.should.equal 120
21
+ @v.width.should.equal 100
22
+ @v.height.should.equal 200
23
+ end
24
+
25
+ it "Insets" do
26
+ @v.inset!(10, 10)
27
+ @v.frame.should.close CGRectMake(20, 30, 80, 180), delta
28
+ end
29
+
30
+ it "Insets" do
31
+ @v.inset!(5, 20)
32
+ @v.frame.should.close CGRectMake(15, 40, 90, 160), delta
33
+ end
34
+
35
+ it "Insets" do
36
+ @v.inset!(-5, -20)
37
+ @v.frame.should.close CGRectMake(5, 0, 110, 240), delta
13
38
  end
14
39
  end
15
40
  end
@@ -0,0 +1,43 @@
1
+ if PurplishFrame.osx?
2
+ class CGRect
3
+ def close?(to, delta)
4
+ origin.x.close?(to.origin.x, delta) && origin.y.close?(to.origin.y, delta) && size.width.close?(to.size.width, delta) && size.height.close?(to.size.height, delta)
5
+ end
6
+ end
7
+
8
+ describe "NSView" do
9
+ delta = 0.0001
10
+ before do
11
+ @v = NSView.alloc.initWithFrame([[10, 20], [100, 200]])
12
+ end
13
+
14
+ it "Accessing" do
15
+ @v.left.should.equal 10
16
+ @v.right.should.equal 110
17
+ @v.top.should.equal 220
18
+ @v.bottom.should.equal 20
19
+ @v.center_x.should.equal 60
20
+ @v.center_y.should.equal 120
21
+ @v.width.should.equal 100
22
+ @v.height.should.equal 200
23
+ end
24
+
25
+ it "Insets" do
26
+ #Returns CGRect!
27
+ @v.inset!(10, 10)
28
+ @v.frame.should.close CGRectMake(20, 30, 80, 180), delta
29
+ end
30
+
31
+ it "Insets" do
32
+ #Returns CGRect!
33
+ @v.inset!(5, 20)
34
+ @v.frame.should.close CGRectMake(15, 40, 90, 160), delta
35
+ end
36
+
37
+ it "Insets" do
38
+ #Returns CGRect!
39
+ @v.inset!(-5, -20)
40
+ @v.frame.should.close CGRectMake(5, 0, 110, 240), delta
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purplish-frame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hwee-Boon Yar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-06 00:00:00.000000000 Z
11
+ date: 2015-12-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make working with rects, sizes and points more convenient with RubyMotion
14
14
  for iOS & OS X
@@ -19,7 +19,6 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
21
  - Gemfile
22
- - Gemfile.lock
23
22
  - LICENSE
24
23
  - README.md
25
24
  - Rakefile
@@ -56,6 +55,7 @@ files:
56
55
  - spec/ui/ios/ui_screen_spec.rb
57
56
  - spec/ui/ios/ui_view_spec.rb
58
57
  - spec/ui/osx/ns_screen_spec.rb
58
+ - spec/ui/osx/ns_view_spec.rb
59
59
  homepage: https://github.com/hboon/purplish-frame
60
60
  licenses:
61
61
  - BSD
@@ -91,4 +91,5 @@ test_files:
91
91
  - spec/ui/ios/ui_screen_spec.rb
92
92
  - spec/ui/ios/ui_view_spec.rb
93
93
  - spec/ui/osx/ns_screen_spec.rb
94
+ - spec/ui/osx/ns_view_spec.rb
94
95
  has_rdoc:
data/Gemfile.lock DELETED
@@ -1,14 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- purplish-frame (0.0.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- ruby
12
-
13
- DEPENDENCIES
14
- purplish-frame!