purplish-frame 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/purplish-frame/{cg_size.rb → non-ui/cg_size.rb} +4 -0
- data/lib/purplish-frame/{osx → non-ui/osx}/ns_size.rb +4 -0
- data/lib/purplish-frame/ui/ios/cocoa_touch_view.rb +13 -0
- data/lib/purplish-frame/ui/ios/ui_screen.rb +11 -0
- data/lib/purplish-frame/ui/ios/ui_view.rb +47 -0
- data/lib/purplish-frame/ui/osx/cocoa_view.rb +71 -0
- data/lib/purplish-frame/ui/osx/ns_screen.rb +3 -0
- data/lib/purplish-frame/ui/osx/ns_view.rb +3 -0
- data/lib/purplish-frame/ui/osx/ns_window.rb +11 -0
- data/lib/purplish-frame/ui/view.rb +99 -0
- data/lib/purplish-frame/version.rb +1 -1
- data/spec/ui/ios/ui_screen_spec.rb +15 -0
- data/spec/ui/ios/ui_view_spec.rb +15 -0
- data/spec/ui/osx/ns_screen_spec.rb +15 -0
- metadata +39 -25
- /data/lib/purplish-frame/{can_scale_width_height.rb → non-ui/can_scale_width_height.rb} +0 -0
- /data/lib/purplish-frame/{cg_point.rb → non-ui/cg_point.rb} +0 -0
- /data/lib/purplish-frame/{cg_rect.rb → non-ui/cg_rect.rb} +0 -0
- /data/lib/purplish-frame/{ns_array.rb → non-ui/ns_array.rb} +0 -0
- /data/lib/purplish-frame/{osx → non-ui/osx}/ns_array.rb +0 -0
- /data/lib/purplish-frame/{osx → non-ui/osx}/ns_point.rb +0 -0
- /data/lib/purplish-frame/{osx → non-ui/osx}/ns_rect.rb +0 -0
- /data/lib/purplish-frame/{point.rb → non-ui/point.rb} +0 -0
- /data/lib/purplish-frame/{rect.rb → non-ui/rect.rb} +0 -0
- /data/spec/{cg_point_spec.rb → non-ui/cg_point_spec.rb} +0 -0
- /data/spec/{cg_rect_spec.rb → non-ui/cg_rect_spec.rb} +0 -0
- /data/spec/{cg_size.spec.rb → non-ui/cg_size.spec.rb} +0 -0
- /data/spec/{osx → non-ui/osx}/ns_point_spec.rb +0 -0
- /data/spec/{osx → non-ui/osx}/ns_rect_spec.rb +0 -0
- /data/spec/{osx → non-ui/osx}/ns_size_spec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ad510018fc944c6b60933bc2a4350c38cbb47a
|
4
|
+
data.tar.gz: 662ea93c6e9385bc70fd2a5759254ebe8130094e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83fa589d0497ebaf6c6d622acb74978bfafa6f63d289897add92bdc8c9ee71550dd970a33bc7104037795105b1489742b214edcd3e8673d44528db6f958f07da
|
7
|
+
data.tar.gz: c470f974b54d5c79caf4c203009adf50c7de5744d336208ab5133f44a7ae68a57ef38ad590e4c5cb6c70ad6fa729321bc1b7968c616d57c2e5da35f6cdc92dc6
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class UIView
|
2
|
+
include PurplishFrame::CocoaTouchView
|
3
|
+
|
4
|
+
def view_frame
|
5
|
+
frame
|
6
|
+
end
|
7
|
+
|
8
|
+
def top=(y)
|
9
|
+
f = frame
|
10
|
+
f.origin.y = y
|
11
|
+
self.frame = f
|
12
|
+
end
|
13
|
+
|
14
|
+
def bottom=(bottom)
|
15
|
+
f = frame
|
16
|
+
f.origin.y = bottom - f.size.height
|
17
|
+
self.frame = f
|
18
|
+
end
|
19
|
+
|
20
|
+
def height=(height)
|
21
|
+
f = frame
|
22
|
+
f.size.height = height
|
23
|
+
self.frame = f
|
24
|
+
end
|
25
|
+
|
26
|
+
def origin_relative_to_superview(v)
|
27
|
+
sup = superview
|
28
|
+
offset = CGPointZero
|
29
|
+
|
30
|
+
#if ([sup isKindOfClass:[UIScrollView class]]) {
|
31
|
+
#offset = ((UIScrollView*)sup).contentOffset
|
32
|
+
#}
|
33
|
+
|
34
|
+
if !sup || v == sup
|
35
|
+
return CGPoint.new(left-offset.x, top-offset.y)
|
36
|
+
else
|
37
|
+
d = sup.origin_relative_to_superview(v)
|
38
|
+
return CGPoint.new(left+d.x-offset.x, top+d.y-offset.y)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def move_origin_relative_to_superview(v)
|
43
|
+
pt = origin_relative_to_superview(v)
|
44
|
+
self.left = pt.x
|
45
|
+
self.top = pt.y
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module PurplishFrame
|
2
|
+
module CocoaView
|
3
|
+
include View
|
4
|
+
|
5
|
+
def view_frame
|
6
|
+
frame
|
7
|
+
end
|
8
|
+
|
9
|
+
def top
|
10
|
+
frame.origin.y + frame.size.height
|
11
|
+
end
|
12
|
+
|
13
|
+
def top=(y)
|
14
|
+
f = frame
|
15
|
+
f.origin.y = y - height
|
16
|
+
self.frame = f
|
17
|
+
end
|
18
|
+
|
19
|
+
def bottom
|
20
|
+
frame.origin.y
|
21
|
+
end
|
22
|
+
|
23
|
+
def bottom=(bottom)
|
24
|
+
f = frame
|
25
|
+
f.origin.y = bottom
|
26
|
+
self.frame = f
|
27
|
+
end
|
28
|
+
|
29
|
+
def center
|
30
|
+
NSMakePoint(left+width/2, top-height/2)
|
31
|
+
end
|
32
|
+
|
33
|
+
def center=(pt)
|
34
|
+
#We need to check because pt might be HIPoint or some Boxed type
|
35
|
+
pt = pt.to_point if pt.respond_to? :to_point
|
36
|
+
f = frame
|
37
|
+
f.origin.x = pt.x-width/2
|
38
|
+
f.origin.y = pt.y-height/2
|
39
|
+
self.frame = f
|
40
|
+
end
|
41
|
+
|
42
|
+
def height=(height)
|
43
|
+
f = frame
|
44
|
+
f.origin.y -= height - frame.size.height
|
45
|
+
f.size.height = height
|
46
|
+
self.frame = f
|
47
|
+
end
|
48
|
+
|
49
|
+
#def origin_relative_to_superview(v)
|
50
|
+
#sup = superview
|
51
|
+
#offset = CGPointZero
|
52
|
+
|
53
|
+
#if ([sup isKindOfClass:[UIScrollView class]]) {
|
54
|
+
#offset = ((UIScrollView*)sup).contentOffset
|
55
|
+
#}
|
56
|
+
|
57
|
+
#if !sup || v == sup
|
58
|
+
#return CGPoint.new(left-offset.x, top-offset.y)
|
59
|
+
#else
|
60
|
+
#d = sup.origin_relative_to_superview(v)
|
61
|
+
#return CGPoint.new(left+d.x-offset.x, top+d.y-offset.y)
|
62
|
+
#end
|
63
|
+
#end
|
64
|
+
|
65
|
+
#def move_origin_relative_to_superview(v)
|
66
|
+
#pt = origin_relative_to_superview(v)
|
67
|
+
#self.left = pt.x
|
68
|
+
#self.top = pt.y
|
69
|
+
#end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module PurplishFrame
|
2
|
+
module View
|
3
|
+
def left
|
4
|
+
view_frame.origin.x
|
5
|
+
end
|
6
|
+
|
7
|
+
def left=(x)
|
8
|
+
f = frame
|
9
|
+
f.origin.x = x
|
10
|
+
self.frame = f
|
11
|
+
end
|
12
|
+
|
13
|
+
def right
|
14
|
+
view_frame.origin.x + view_frame.size.width
|
15
|
+
end
|
16
|
+
|
17
|
+
def right=(right)
|
18
|
+
f = frame
|
19
|
+
f.origin.x = right - f.size.width
|
20
|
+
self.frame = f
|
21
|
+
end
|
22
|
+
|
23
|
+
def center_x
|
24
|
+
center.x
|
25
|
+
end
|
26
|
+
|
27
|
+
def center_x=(center_x)
|
28
|
+
self.center = [center_x, center.y]
|
29
|
+
end
|
30
|
+
|
31
|
+
def center_y
|
32
|
+
center.y
|
33
|
+
end
|
34
|
+
|
35
|
+
def center_y=(center_y)
|
36
|
+
self.center = [center.x, center_y]
|
37
|
+
end
|
38
|
+
|
39
|
+
def width
|
40
|
+
view_frame.size.width
|
41
|
+
end
|
42
|
+
|
43
|
+
def width=(width)
|
44
|
+
f = frame
|
45
|
+
f.size.width = width
|
46
|
+
self.frame = f
|
47
|
+
end
|
48
|
+
|
49
|
+
def height
|
50
|
+
view_frame.size.height
|
51
|
+
end
|
52
|
+
|
53
|
+
def size_width_to_fit
|
54
|
+
h = height
|
55
|
+
sizeToFit
|
56
|
+
self.height = h
|
57
|
+
end
|
58
|
+
|
59
|
+
def size_width_to_fit_align_right
|
60
|
+
x = right
|
61
|
+
size_width_to_fit
|
62
|
+
self.right = x
|
63
|
+
end
|
64
|
+
|
65
|
+
def size_width_to_fit_max(f)
|
66
|
+
size_width_to_fit
|
67
|
+
self.width = f if width > f
|
68
|
+
end
|
69
|
+
|
70
|
+
def size_width_to_fit_min(f)
|
71
|
+
size_width_to_fit
|
72
|
+
self.width = f if width < f
|
73
|
+
end
|
74
|
+
|
75
|
+
def size_height_to_fit
|
76
|
+
w = width
|
77
|
+
#Otherwise it doesn't expand short UILabel when it's too short to fit longer text
|
78
|
+
self.height = 1000
|
79
|
+
sizeToFit
|
80
|
+
self.width = w
|
81
|
+
end
|
82
|
+
|
83
|
+
def size_height_to_fit_align_bottom
|
84
|
+
y = bottom
|
85
|
+
size_height_to_fit
|
86
|
+
self.bottom = y
|
87
|
+
end
|
88
|
+
|
89
|
+
def size_height_to_fit_max(f)
|
90
|
+
size_height_to_fit
|
91
|
+
self.height = f if height > f
|
92
|
+
end
|
93
|
+
|
94
|
+
def size_height_to_fit_min(f)
|
95
|
+
size_height_to_fit
|
96
|
+
self.height = f if height < f
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if PurplishFrame.ios?
|
2
|
+
describe "UIScreen" do
|
3
|
+
it "Accessing" do
|
4
|
+
screen = UIScreen.mainScreen
|
5
|
+
screen.left.should.equal 0
|
6
|
+
screen.right.should.equal screen.bounds.size.width
|
7
|
+
screen.top.should.equal 0
|
8
|
+
screen.bottom.should.equal screen.bounds.size.height
|
9
|
+
screen.center_x.should.equal screen.bounds.size.width/2
|
10
|
+
screen.center_y.should.equal screen.bounds.size.height/2
|
11
|
+
screen.width.should.equal screen.bounds.size.width
|
12
|
+
screen.height.should.equal screen.bounds.size.height
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if PurplishFrame.ios?
|
2
|
+
describe "UIView" do
|
3
|
+
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
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
if PurplishFrame.osx?
|
2
|
+
describe "NSScreen" do
|
3
|
+
it "Accessing" do
|
4
|
+
screen = NSScreen.mainScreen
|
5
|
+
screen.left.should.equal screen.frame.origin.x
|
6
|
+
screen.right.should.equal screen.frame.size.width
|
7
|
+
screen.top.should.equal (screen.frame.origin.y+screen.frame.size.height)
|
8
|
+
screen.bottom.should.equal screen.frame.origin.y
|
9
|
+
screen.center_x.should.equal (screen.frame.origin.x+screen.frame.size.width/2)
|
10
|
+
screen.center_y.should.equal (screen.frame.origin.y+screen.frame.size.height/2)
|
11
|
+
screen.width.should.equal screen.frame.size.width
|
12
|
+
screen.height.should.equal screen.frame.size.height
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2015-12-06 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
|
@@ -25,26 +25,37 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- app/app_delegate.rb
|
27
27
|
- lib/purplish-frame.rb
|
28
|
-
- lib/purplish-frame/can_scale_width_height.rb
|
29
|
-
- lib/purplish-frame/cg_point.rb
|
30
|
-
- lib/purplish-frame/cg_rect.rb
|
31
|
-
- lib/purplish-frame/cg_size.rb
|
32
|
-
- lib/purplish-frame/ns_array.rb
|
33
|
-
- lib/purplish-frame/osx/ns_array.rb
|
34
|
-
- lib/purplish-frame/osx/ns_point.rb
|
35
|
-
- lib/purplish-frame/osx/ns_rect.rb
|
36
|
-
- lib/purplish-frame/osx/ns_size.rb
|
37
|
-
- lib/purplish-frame/point.rb
|
28
|
+
- lib/purplish-frame/non-ui/can_scale_width_height.rb
|
29
|
+
- lib/purplish-frame/non-ui/cg_point.rb
|
30
|
+
- lib/purplish-frame/non-ui/cg_rect.rb
|
31
|
+
- lib/purplish-frame/non-ui/cg_size.rb
|
32
|
+
- lib/purplish-frame/non-ui/ns_array.rb
|
33
|
+
- lib/purplish-frame/non-ui/osx/ns_array.rb
|
34
|
+
- lib/purplish-frame/non-ui/osx/ns_point.rb
|
35
|
+
- lib/purplish-frame/non-ui/osx/ns_rect.rb
|
36
|
+
- lib/purplish-frame/non-ui/osx/ns_size.rb
|
37
|
+
- lib/purplish-frame/non-ui/point.rb
|
38
|
+
- lib/purplish-frame/non-ui/rect.rb
|
38
39
|
- lib/purplish-frame/purplish_frame.rb
|
39
|
-
- lib/purplish-frame/
|
40
|
+
- lib/purplish-frame/ui/ios/cocoa_touch_view.rb
|
41
|
+
- lib/purplish-frame/ui/ios/ui_screen.rb
|
42
|
+
- lib/purplish-frame/ui/ios/ui_view.rb
|
43
|
+
- lib/purplish-frame/ui/osx/cocoa_view.rb
|
44
|
+
- lib/purplish-frame/ui/osx/ns_screen.rb
|
45
|
+
- lib/purplish-frame/ui/osx/ns_view.rb
|
46
|
+
- lib/purplish-frame/ui/osx/ns_window.rb
|
47
|
+
- lib/purplish-frame/ui/view.rb
|
40
48
|
- lib/purplish-frame/version.rb
|
41
49
|
- purplish-frame.gemspec
|
42
|
-
- spec/cg_point_spec.rb
|
43
|
-
- spec/cg_rect_spec.rb
|
44
|
-
- spec/cg_size.spec.rb
|
45
|
-
- spec/osx/ns_point_spec.rb
|
46
|
-
- spec/osx/ns_rect_spec.rb
|
47
|
-
- spec/osx/ns_size_spec.rb
|
50
|
+
- spec/non-ui/cg_point_spec.rb
|
51
|
+
- spec/non-ui/cg_rect_spec.rb
|
52
|
+
- spec/non-ui/cg_size.spec.rb
|
53
|
+
- spec/non-ui/osx/ns_point_spec.rb
|
54
|
+
- spec/non-ui/osx/ns_rect_spec.rb
|
55
|
+
- spec/non-ui/osx/ns_size_spec.rb
|
56
|
+
- spec/ui/ios/ui_screen_spec.rb
|
57
|
+
- spec/ui/ios/ui_view_spec.rb
|
58
|
+
- spec/ui/osx/ns_screen_spec.rb
|
48
59
|
homepage: https://github.com/hboon/purplish-frame
|
49
60
|
licenses:
|
50
61
|
- BSD
|
@@ -71,10 +82,13 @@ specification_version: 4
|
|
71
82
|
summary: Make working with rects, sizes and points more convenient with RubyMotion
|
72
83
|
for iOS & OS X
|
73
84
|
test_files:
|
74
|
-
- spec/cg_point_spec.rb
|
75
|
-
- spec/cg_rect_spec.rb
|
76
|
-
- spec/cg_size.spec.rb
|
77
|
-
- spec/osx/ns_point_spec.rb
|
78
|
-
- spec/osx/ns_rect_spec.rb
|
79
|
-
- spec/osx/ns_size_spec.rb
|
85
|
+
- spec/non-ui/cg_point_spec.rb
|
86
|
+
- spec/non-ui/cg_rect_spec.rb
|
87
|
+
- spec/non-ui/cg_size.spec.rb
|
88
|
+
- spec/non-ui/osx/ns_point_spec.rb
|
89
|
+
- spec/non-ui/osx/ns_rect_spec.rb
|
90
|
+
- spec/non-ui/osx/ns_size_spec.rb
|
91
|
+
- spec/ui/ios/ui_screen_spec.rb
|
92
|
+
- spec/ui/ios/ui_view_spec.rb
|
93
|
+
- spec/ui/osx/ns_screen_spec.rb
|
80
94
|
has_rdoc:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|