purplish-frame 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/purplish-frame/ui/ca_layer.rb +16 -0
- data/lib/purplish-frame/ui/ios/ca_layer.rb +32 -0
- data/lib/purplish-frame/ui/osx/ca_layer.rb +41 -0
- data/lib/purplish-frame/version.rb +1 -1
- data/lib/purplish-frame.rb +32 -15
- data/spec/ui/ios/ca_layer_spec.rb +43 -0
- data/spec/ui/osx/ca_layer_spec.rb +46 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52639b6f88197722c13732d3f88449886bcac6af
|
4
|
+
data.tar.gz: 6e87358e34eecfca43a468383a400bf918cdf186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3c1f78eb0e33e54e3c15e7ac22ee650fc588bbc51b1331639342fe8c27a95d87d5f4371207e450c431310e6af44660b4ab4044cb8edc45b83ee08ffbd0adf6
|
7
|
+
data.tar.gz: 486871e5665d586c6d4e9a3738d15b2493a2deeab88cf505cd02dbd41214561c45d2e53d5d95d871cfcdd0b8fbaee1ece47709e7b0763df75e576519cf12570b
|
data/README.md
CHANGED
@@ -24,14 +24,14 @@ rect.center_y
|
|
24
24
|
=> #30
|
25
25
|
```
|
26
26
|
|
27
|
-
Similar usage for UIView for iOS and NSView, NSSize, NSPoint, NSRect for OS X.
|
27
|
+
Similar usage for UIView for iOS and NSView, NSSize, NSPoint, NSRect for OS X, CALayer for both platforms.
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
rect = CGRectMake(10, -20, 100, 100)
|
31
31
|
rect.inset(5, 20)
|
32
32
|
=> #<CGRect origin=#<CGPoint x=15.0 y=0.0> size=#<CGSize width=90.0 height=60.0>>
|
33
33
|
```
|
34
|
-
Similar usage for UIView for iOS and NSView, NSRect for OS X.
|
34
|
+
Similar usage for UIView for iOS and NSView, NSRect for OS X, CALayer for both platforms.
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
CGSize.new(100, 100).scale_to_fit(CGSize.new(10, 10))
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CALayer
|
2
|
+
include PurplishFrame::View
|
3
|
+
|
4
|
+
def view_frame
|
5
|
+
frame
|
6
|
+
end
|
7
|
+
|
8
|
+
def center=(pt)
|
9
|
+
#We need to check because pt might be HIPoint or some Boxed type
|
10
|
+
pt = pt.to_point if pt.respond_to? :to_point
|
11
|
+
f = frame
|
12
|
+
f.origin.x = pt.x-width/2
|
13
|
+
f.origin.y = pt.y-height/2
|
14
|
+
self.frame = f
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class CALayer
|
2
|
+
def center
|
3
|
+
CGPointMake(left+width/2, top+height/2)
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
def top
|
8
|
+
frame.origin.y
|
9
|
+
end
|
10
|
+
|
11
|
+
def top=(y)
|
12
|
+
f = frame
|
13
|
+
f.origin.y = y
|
14
|
+
self.frame = f
|
15
|
+
end
|
16
|
+
|
17
|
+
def bottom
|
18
|
+
frame.origin.y + frame.size.height
|
19
|
+
end
|
20
|
+
|
21
|
+
def bottom=(bottom)
|
22
|
+
f = frame
|
23
|
+
f.origin.y = bottom - f.size.height
|
24
|
+
self.frame = f
|
25
|
+
end
|
26
|
+
|
27
|
+
def height=(height)
|
28
|
+
f = frame
|
29
|
+
f.size.height = height
|
30
|
+
self.frame = f
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class CALayer
|
2
|
+
def center
|
3
|
+
NSMakePoint(left+width/2, top-height/2)
|
4
|
+
end
|
5
|
+
|
6
|
+
def center=(pt)
|
7
|
+
#We need to check because pt might be HIPoint or some Boxed type
|
8
|
+
pt = pt.to_point if pt.respond_to? :to_point
|
9
|
+
f = frame
|
10
|
+
f.origin.x = pt.x-width/2
|
11
|
+
f.origin.y = pt.y-height/2
|
12
|
+
self.frame = f
|
13
|
+
end
|
14
|
+
|
15
|
+
def top
|
16
|
+
frame.origin.y + frame.size.height
|
17
|
+
end
|
18
|
+
|
19
|
+
def top=(y)
|
20
|
+
f = frame
|
21
|
+
f.origin.y = y - height
|
22
|
+
self.frame = f
|
23
|
+
end
|
24
|
+
|
25
|
+
def bottom
|
26
|
+
frame.origin.y
|
27
|
+
end
|
28
|
+
|
29
|
+
def bottom=(bottom)
|
30
|
+
f = frame
|
31
|
+
f.origin.y = bottom
|
32
|
+
self.frame = f
|
33
|
+
end
|
34
|
+
|
35
|
+
def height=(height)
|
36
|
+
f = frame
|
37
|
+
f.origin.y -= height - frame.size.height
|
38
|
+
f.size.height = height
|
39
|
+
self.frame = f
|
40
|
+
end
|
41
|
+
end
|
data/lib/purplish-frame.rb
CHANGED
@@ -2,25 +2,42 @@ unless defined?(Motion::Project::Config)
|
|
2
2
|
raise "This file must be required within a RubyMotion project Rakefile."
|
3
3
|
end
|
4
4
|
|
5
|
+
class Motion::Project::App
|
6
|
+
def self.osx?
|
7
|
+
respond_to?(:template) && template == :osx
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
Motion::Project::App.setup do |app|
|
6
12
|
Dir.glob(File.join(File.dirname(__FILE__), 'purplish-frame/**/*.rb')).each do |file|
|
7
|
-
|
13
|
+
exclude = false
|
14
|
+
if Motion::Project::App.osx?
|
15
|
+
if file.include? '/ios/'
|
16
|
+
exclude = true
|
17
|
+
end
|
18
|
+
else
|
19
|
+
if file.include? '/osx/'
|
20
|
+
exclude = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
app.files.unshift(file) unless exclude
|
8
24
|
end
|
9
25
|
|
10
26
|
#Just to be safe. Did not work reliably with ENV['experimental_dependency']=1
|
11
27
|
core_lib = File.join(File.dirname(__FILE__), 'purplish-frame')
|
12
|
-
|
13
|
-
|
14
|
-
"#{core_lib}/ui/
|
15
|
-
|
16
|
-
"#{core_lib}/ui/osx/
|
17
|
-
"#{core_lib}/ui/osx/
|
18
|
-
"#{core_lib}/ui/osx/
|
19
|
-
|
20
|
-
"#{core_lib}/
|
21
|
-
"#{core_lib}/
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
28
|
+
dependencies = {}
|
29
|
+
if Motion::Project::App.osx?
|
30
|
+
dependencies["#{core_lib}/ui/osx/ns_view.rb"] = ["#{core_lib}/ui/osx/cocoa_view.rb"]
|
31
|
+
dependencies["#{core_lib}/ui/osx/ns_screen.rb"] = ["#{core_lib}/ui/osx/cocoa_view.rb"]
|
32
|
+
dependencies["#{core_lib}/ui/osx/ns_window.rb"] = ["#{core_lib}/ui/osx/cocoa_view.rb"]
|
33
|
+
dependencies["#{core_lib}/non-ui/osx/ns_size.rb"] = ["#{core_lib}/non-ui/can_scale_width_height.rb"]
|
34
|
+
dependencies["#{core_lib}/non-ui/osx/ns_image.rb"] = ["#{core_lib}/non-ui/has_size_width_height.rb"]
|
35
|
+
else
|
36
|
+
dependencies["#{core_lib}/ui/ios/ui_screen.rb"] = ["#{core_lib}/ui/ios/cocoa_touch_view.rb"]
|
37
|
+
dependencies["#{core_lib}/ui/ios/ui_view.rb"] = ["#{core_lib}/ui/ios/cocoa_touch_view.rb"]
|
38
|
+
dependencies["#{core_lib}/non-ui/ios/ui_image.rb"] = ["#{core_lib}/non-ui/has_size_width_height.rb"]
|
39
|
+
end
|
40
|
+
dependencies["#{core_lib}/non-ui/cg_size.rb"] = ["#{core_lib}/non-ui/can_scale_width_height.rb"]
|
41
|
+
dependencies["#{core_lib}/ui/ca_layer.rb"] = ["#{core_lib}/ui/view.rb"]
|
42
|
+
app.files_dependencies(dependencies)
|
26
43
|
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
|
8
|
+
describe "CALayer" do
|
9
|
+
delta = 0.0001
|
10
|
+
before do
|
11
|
+
@v = CALayer.new.tap do |l|
|
12
|
+
l.frame = [[10, 20], [100, 200]]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Accessing" do
|
17
|
+
@v.left.should.equal 10
|
18
|
+
@v.right.should.equal 110
|
19
|
+
@v.top.should.equal 20
|
20
|
+
@v.bottom.should.equal 220
|
21
|
+
@v.center_x.should.equal 60
|
22
|
+
@v.center_y.should.equal 120
|
23
|
+
@v.width.should.equal 100
|
24
|
+
@v.height.should.equal 200
|
25
|
+
end
|
26
|
+
|
27
|
+
it "Insets" do
|
28
|
+
@v.inset!(10, 10)
|
29
|
+
@v.frame.should.close CGRectMake(20, 30, 80, 180), delta
|
30
|
+
end
|
31
|
+
|
32
|
+
it "Insets" do
|
33
|
+
@v.inset!(5, 20)
|
34
|
+
@v.frame.should.close CGRectMake(15, 40, 90, 160), delta
|
35
|
+
end
|
36
|
+
|
37
|
+
it "Insets" do
|
38
|
+
@v.inset!(-5, -20)
|
39
|
+
@v.frame.should.close CGRectMake(5, 0, 110, 240), delta
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,46 @@
|
|
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 "CALayer" do
|
9
|
+
delta = 0.0001
|
10
|
+
before do
|
11
|
+
@v = CALayer.new.tap do |l|
|
12
|
+
l.frame = [[10, 20], [100, 200]]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Accessing" do
|
17
|
+
@v.left.should.equal 10
|
18
|
+
@v.right.should.equal 110
|
19
|
+
@v.top.should.equal 220
|
20
|
+
@v.bottom.should.equal 20
|
21
|
+
@v.center_x.should.equal 60
|
22
|
+
@v.center_y.should.equal 120
|
23
|
+
@v.width.should.equal 100
|
24
|
+
@v.height.should.equal 200
|
25
|
+
end
|
26
|
+
|
27
|
+
it "Insets" do
|
28
|
+
#Returns CGRect!
|
29
|
+
@v.inset!(10, 10)
|
30
|
+
@v.frame.should.close CGRectMake(20, 30, 80, 180), delta
|
31
|
+
end
|
32
|
+
|
33
|
+
it "Insets" do
|
34
|
+
#Returns CGRect!
|
35
|
+
@v.inset!(5, 20)
|
36
|
+
@v.frame.should.close CGRectMake(15, 40, 90, 160), delta
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Insets" do
|
40
|
+
#Returns CGRect!
|
41
|
+
@v.inset!(-5, -20)
|
42
|
+
@v.frame.should.close CGRectMake(5, 0, 110, 240), delta
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purplish-frame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hwee-Boon Yar
|
@@ -40,9 +40,12 @@ files:
|
|
40
40
|
- lib/purplish-frame/non-ui/point.rb
|
41
41
|
- lib/purplish-frame/non-ui/rect.rb
|
42
42
|
- lib/purplish-frame/purplish_frame.rb
|
43
|
+
- lib/purplish-frame/ui/ca_layer.rb
|
44
|
+
- lib/purplish-frame/ui/ios/ca_layer.rb
|
43
45
|
- lib/purplish-frame/ui/ios/cocoa_touch_view.rb
|
44
46
|
- lib/purplish-frame/ui/ios/ui_screen.rb
|
45
47
|
- lib/purplish-frame/ui/ios/ui_view.rb
|
48
|
+
- lib/purplish-frame/ui/osx/ca_layer.rb
|
46
49
|
- lib/purplish-frame/ui/osx/cocoa_view.rb
|
47
50
|
- lib/purplish-frame/ui/osx/ns_screen.rb
|
48
51
|
- lib/purplish-frame/ui/osx/ns_view.rb
|
@@ -56,8 +59,10 @@ files:
|
|
56
59
|
- spec/non-ui/osx/ns_point_spec.rb
|
57
60
|
- spec/non-ui/osx/ns_rect_spec.rb
|
58
61
|
- spec/non-ui/osx/ns_size_spec.rb
|
62
|
+
- spec/ui/ios/ca_layer_spec.rb
|
59
63
|
- spec/ui/ios/ui_screen_spec.rb
|
60
64
|
- spec/ui/ios/ui_view_spec.rb
|
65
|
+
- spec/ui/osx/ca_layer_spec.rb
|
61
66
|
- spec/ui/osx/ns_screen_spec.rb
|
62
67
|
- spec/ui/osx/ns_view_spec.rb
|
63
68
|
homepage: https://github.com/hboon/purplish-frame
|
@@ -92,8 +97,10 @@ test_files:
|
|
92
97
|
- spec/non-ui/osx/ns_point_spec.rb
|
93
98
|
- spec/non-ui/osx/ns_rect_spec.rb
|
94
99
|
- spec/non-ui/osx/ns_size_spec.rb
|
100
|
+
- spec/ui/ios/ca_layer_spec.rb
|
95
101
|
- spec/ui/ios/ui_screen_spec.rb
|
96
102
|
- spec/ui/ios/ui_view_spec.rb
|
103
|
+
- spec/ui/osx/ca_layer_spec.rb
|
97
104
|
- spec/ui/osx/ns_screen_spec.rb
|
98
105
|
- spec/ui/osx/ns_view_spec.rb
|
99
106
|
has_rdoc:
|