sugarcube 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -24
- data/lib/sugarcube/adjust.rb +77 -75
- data/lib/sugarcube/core_graphics.rb +60 -58
- data/lib/sugarcube/notifications.rb +0 -4
- data/lib/sugarcube/{string.rb → nsstring.rb} +0 -0
- data/lib/sugarcube/nsurl.rb +7 -0
- data/lib/sugarcube/uiview.rb +1 -1
- data/lib/sugarcube/version.rb +1 -1
- metadata +7 -6
data/README.md
CHANGED
@@ -17,7 +17,7 @@ view << subview.
|
|
17
17
|
|
18
18
|
The basic idea of sugarcube is to turn some operations on their head. Insead of
|
19
19
|
|
20
|
-
|
20
|
+
UIApplication.sharedApplication.openURL(NSUrl.URLWithString(url))
|
21
21
|
|
22
22
|
How about:
|
23
23
|
|
@@ -209,14 +209,15 @@ test[:my] = 'new'
|
|
209
209
|
###### Is it `CGMakeRect` or `CGRectMake`?
|
210
210
|
|
211
211
|
Instead, just use `Rect`, `Size` and `Point`. These are namespaced in
|
212
|
-
`SugarCube` module, but I recommend you `include
|
212
|
+
`SugarCube::CoreGraphics` module, but I recommend you `include
|
213
|
+
SugarCube::CoreGraphics` in app_delegate.rb.
|
213
214
|
|
214
215
|
```ruby
|
215
|
-
f =
|
216
|
-
o =
|
217
|
-
s =
|
216
|
+
f = Rect(view.frame) # converts a CGRect into a CGRectArray
|
217
|
+
o = Point(view.frame.origin) # converts a CGPoint into a CGPointArray
|
218
|
+
s = Size(view.frame.size) # converts a CGSize into a CGSizeArray
|
218
219
|
|
219
|
-
# lots of other conversions are possible.
|
220
|
+
# lots of other conversions are possible.
|
220
221
|
# 4 numbers
|
221
222
|
f = Rect(x, y, w, h)
|
222
223
|
# or two arrays
|
@@ -234,11 +235,11 @@ jQuery-like animation methods.
|
|
234
235
|
|
235
236
|
```ruby
|
236
237
|
# default timeout is 0.3
|
237
|
-
view.
|
238
|
+
view.fade_out { |view|
|
238
239
|
view.removeFromSuperview
|
239
240
|
}
|
240
241
|
# options:
|
241
|
-
view.
|
242
|
+
view.fade_out(0.5, delay: 0,
|
242
243
|
options: UIViewAnimationOptionCurveLinear,
|
243
244
|
opacity: 0.5) { |view|
|
244
245
|
view.removeFromSuperview
|
@@ -253,28 +254,30 @@ view.delta_to([0, 100]) # move over 0, down 100, from current position
|
|
253
254
|
Pixel pushing is an unfortunate but necessary evil. Well, at least we can make
|
254
255
|
it a little less painful.
|
255
256
|
|
256
|
-
These methods help you adjust the frame of a view. They are in the
|
257
|
-
module so as not to conflict. If you don't want the prefix,
|
258
|
-
app_delegate.rb
|
257
|
+
These methods help you adjust the frame of a view. They are in the
|
258
|
+
`SugarCube::Adjust` module so as not to conflict. If you don't want the prefix,
|
259
|
+
`include SugarCube::Adjust` in app_delegate.rb
|
260
|
+
|
261
|
+
Assume I ran `include SugarCube::Adjust` in these examples.
|
259
262
|
|
260
263
|
```ruby
|
261
264
|
# if you are in the REPL, you might not be able to click on the view you want...
|
262
|
-
>
|
263
|
-
>
|
264
|
-
>
|
265
|
-
>
|
266
|
-
>
|
267
|
-
>
|
268
|
-
>
|
269
|
-
>
|
270
|
-
>
|
271
|
-
>
|
272
|
-
>
|
273
|
-
>
|
265
|
+
> adjust superview.subviews[4].subviews[1]
|
266
|
+
> up 1
|
267
|
+
> down 1 # same as up -1, obviously
|
268
|
+
> left 1
|
269
|
+
> right 1 # same as up -1, obviously
|
270
|
+
> origin 10, 12 # move to x:10, y:12
|
271
|
+
> wider 1
|
272
|
+
> thinner 1
|
273
|
+
> taller 1
|
274
|
+
> shorter 1
|
275
|
+
> size 100, 10 # set size to width:100, height: 10
|
276
|
+
> restore # original frame is saved when you call adjust
|
274
277
|
```
|
275
278
|
|
276
279
|
```ruby
|
277
|
-
> # short versions!
|
280
|
+
> # short versions!
|
278
281
|
> a superview.subviews[4].subviews[1] # this is not uncommon in the REPL
|
279
282
|
> u # up, default value=1
|
280
283
|
> d # down
|
data/lib/sugarcube/adjust.rb
CHANGED
@@ -1,93 +1,95 @@
|
|
1
1
|
module SugarCube
|
2
|
-
|
2
|
+
module Adjust
|
3
|
+
module_function
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
def adjust view=nil
|
6
|
+
return @@sugarcube_view if not view
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
@@sugarcube_view = view
|
9
|
+
@@sugarcube_restore = view.frame
|
10
|
+
view
|
11
|
+
end
|
12
|
+
alias :a :adjust
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
##| ORIGIN
|
15
|
+
def left val=1
|
16
|
+
SugarCube::right -val
|
17
|
+
end
|
18
|
+
alias :l :left
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def right val=1
|
21
|
+
f = @@sugarcube_view.frame
|
22
|
+
f.origin.x += val
|
23
|
+
@@sugarcube_view.frame = f
|
24
|
+
end
|
25
|
+
alias :r :right
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def up val=1
|
28
|
+
SugarCube::down -val
|
29
|
+
end
|
30
|
+
alias :u :up
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def down val=1
|
33
|
+
f = @@sugarcube_view.frame
|
34
|
+
f.origin.y += val
|
35
|
+
@@sugarcube_view.frame = f
|
36
|
+
end
|
37
|
+
alias :d :down
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
def origin x, y=nil
|
40
|
+
f = @@sugarcube_view.frame
|
41
|
+
if y
|
42
|
+
f.origin.x = x
|
43
|
+
f.origin.y = y
|
44
|
+
else
|
45
|
+
f.origin = x
|
46
|
+
end
|
47
|
+
@@sugarcube_view.frame = f
|
45
48
|
end
|
46
|
-
|
47
|
-
end
|
48
|
-
alias :o :origin
|
49
|
+
alias :o :origin
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
##| SIZE
|
52
|
+
def thinner val=1
|
53
|
+
SugarCube::wider -val
|
54
|
+
end
|
55
|
+
alias :n :thinner
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def wider val=1
|
58
|
+
f = @@sugarcube_view.frame
|
59
|
+
f.size.width += val
|
60
|
+
@@sugarcube_view.frame = f
|
61
|
+
end
|
62
|
+
alias :w :wider
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
def taller val=1
|
65
|
+
SugarCube::shorter -val
|
66
|
+
end
|
67
|
+
alias :t :taller
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
def shorter val=1
|
70
|
+
f = @@sugarcube_view.frame
|
71
|
+
f.size.height += val
|
72
|
+
@@sugarcube_view.frame = f
|
73
|
+
end
|
74
|
+
alias :s :shorter
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
def size w, h=nil
|
77
|
+
f = @@sugarcube_view.frame
|
78
|
+
if h
|
79
|
+
f.size.width = w
|
80
|
+
f.size.height = h
|
81
|
+
else
|
82
|
+
f.size = w
|
83
|
+
end
|
84
|
+
@@sugarcube_view.frame = f
|
82
85
|
end
|
83
|
-
|
84
|
-
end
|
85
|
-
alias :z :size
|
86
|
+
alias :z :size
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
##| RESTORE
|
89
|
+
def restore
|
90
|
+
@@sugarcube_view.frame = @@sugarcube_restore
|
91
|
+
end
|
92
|
+
alias :r :restore
|
92
93
|
|
94
|
+
end
|
93
95
|
end
|
@@ -76,74 +76,76 @@ end
|
|
76
76
|
|
77
77
|
|
78
78
|
module SugarCube
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
79
|
+
module CoreGraphics
|
80
|
+
module_function
|
81
|
+
|
82
|
+
def Size(w_or_size, h=nil)
|
83
|
+
if not h
|
84
|
+
if CGSize === w_or_size
|
85
|
+
w = w_or_size.width
|
86
|
+
h = w_or_size.height
|
87
|
+
elsif Array === w_or_size
|
88
|
+
w = w_or_size[0]
|
89
|
+
h = w_or_size[1]
|
90
|
+
else
|
91
|
+
raise RuntimeError.new("Invalid argument sent to Size(#{w_or_size.inspect})")
|
92
|
+
end
|
89
93
|
else
|
90
|
-
|
94
|
+
w = w_or_size
|
91
95
|
end
|
92
|
-
|
93
|
-
w = w_or_size
|
96
|
+
return CGSizeArray.new([w, h])
|
94
97
|
end
|
95
|
-
return CGSizeArray.new([w, h])
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
def Point(x_or_origin, y=nil)
|
100
|
+
if not y
|
101
|
+
if CGPoint === x_or_origin
|
102
|
+
x = x_or_origin.x
|
103
|
+
y = x_or_origin.y
|
104
|
+
elsif Array === x_or_origin
|
105
|
+
x = x_or_origin[0]
|
106
|
+
y = x_or_origin[1]
|
107
|
+
else
|
108
|
+
raise RuntimeError.new("Invalid argument sent to Point(#{x_or_origin.inspect})")
|
109
|
+
end
|
106
110
|
else
|
107
|
-
|
111
|
+
x = x_or_origin
|
108
112
|
end
|
109
|
-
|
110
|
-
x = x_or_origin
|
113
|
+
return CGPointArray.new([x, y])
|
111
114
|
end
|
112
|
-
return CGPointArray.new([x, y])
|
113
|
-
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
116
|
+
# Accepts 2 or 4 arguments. 2 arguments should be a point and a size,
|
117
|
+
# 4 should be x, y, w, h
|
118
|
+
def Rect(x_or_origin, y_or_size=nil, w=nil, h=nil)
|
119
|
+
if not y_or_size
|
120
|
+
if CGRectArray === x_or_origin
|
121
|
+
x = x_or_origin[0][0]
|
122
|
+
y = x_or_origin[0][1]
|
123
|
+
w = x_or_origin[1][0]
|
124
|
+
h = x_or_origin[1][1]
|
125
|
+
elsif CGRect === x_or_origin
|
126
|
+
x = x_or_origin.origin.x
|
127
|
+
y = x_or_origin.origin.y
|
128
|
+
w = x_or_origin.size.width
|
129
|
+
h = x_or_origin.size.height
|
130
|
+
elsif Array === x_or_origin
|
131
|
+
x = x_or_origin[0]
|
132
|
+
y = x_or_origin[1]
|
133
|
+
w = x_or_origin[2]
|
134
|
+
h = x_or_origin[3]
|
135
|
+
else
|
136
|
+
raise RuntimeError.new("Invalid argument sent to Rect(#{x_or_origin.inspect})")
|
137
|
+
end
|
138
|
+
elsif not w and not h
|
139
|
+
x = x_or_origin.x
|
140
|
+
y = x_or_origin.y
|
141
|
+
w = y_or_size.width
|
142
|
+
h = y_or_size.height
|
134
143
|
else
|
135
|
-
|
144
|
+
x = x_or_origin
|
145
|
+
y = y_or_size
|
136
146
|
end
|
137
|
-
|
138
|
-
x = x_or_origin.x
|
139
|
-
y = x_or_origin.y
|
140
|
-
w = y_or_size.width
|
141
|
-
h = y_or_size.height
|
142
|
-
else
|
143
|
-
x = x_or_origin
|
144
|
-
y = y_or_size
|
147
|
+
return CGRectArray.new([[x, y], [w, h]])
|
145
148
|
end
|
146
|
-
return CGRectArray.new([[x, y], [w, h]])
|
147
|
-
end
|
148
149
|
|
150
|
+
end
|
149
151
|
end
|
File without changes
|
data/lib/sugarcube/uiview.rb
CHANGED
@@ -12,7 +12,7 @@ class UIView
|
|
12
12
|
"#{self.superview ? ' child of ' + self.superview.class.name : ''}"
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def fade_out(duration=0.3, options={}, &after)
|
16
16
|
UIView.animateWithDuration(duration,
|
17
17
|
delay: options[:delay] || 0,
|
18
18
|
options: options[:options] || UIViewAnimationOptionCurveLinear,
|
data/lib/sugarcube/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-07-13 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement: &
|
17
|
+
requirement: &70111935636200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70111935636200
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &70111935651940 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70111935651940
|
37
37
|
description: ! 'CocoaTouch/iOS is a *verbose* framework. These extensions hope to
|
38
38
|
make
|
39
39
|
|
@@ -72,7 +72,8 @@ files:
|
|
72
72
|
- lib/sugarcube/fixnum.rb
|
73
73
|
- lib/sugarcube/float.rb
|
74
74
|
- lib/sugarcube/notifications.rb
|
75
|
-
- lib/sugarcube/
|
75
|
+
- lib/sugarcube/nsstring.rb
|
76
|
+
- lib/sugarcube/nsurl.rb
|
76
77
|
- lib/sugarcube/symbol.rb
|
77
78
|
- lib/sugarcube/symbol/symbol_uicolor.rb
|
78
79
|
- lib/sugarcube/uicolor.rb
|