sugarcube 0.16.5 → 0.16.9
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.
- data/README.md +6 -1
- data/app/app_delegate.rb +22 -0
- data/lib/sugarcube/core_graphics.rb +8 -3
- data/lib/sugarcube/nsstring.rb +13 -0
- data/lib/sugarcube/symbol.rb +2 -2
- data/lib/sugarcube/uiview.rb +49 -3
- data/lib/sugarcube/version.rb +1 -1
- data/spec/core_graphics_spec.rb +6 -6
- data/spec/nsstring_spec.rb +20 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -693,7 +693,12 @@ shake offset: 8, # move 8 px left, and 8 px right
|
|
693
693
|
# vigorous nodding - modifying transform.translation.y:
|
694
694
|
view.shake offset: 20, repeat: 10, duration: 5, keypath: 'transform.translation.y'
|
695
695
|
# an adorable wiggle - modifying transform.rotation:
|
696
|
-
|
696
|
+
view.shake offset: 0.1, repeat: 2, duration: 0.5, keypath: 'transform.rotation'
|
697
|
+
|
698
|
+
# this was pulled off warrenm's AHAlertView project. I thought the effect was
|
699
|
+
# awesome, and deserved more attention!
|
700
|
+
# https://github.com/warrenm/AHAlertView
|
701
|
+
view.tumble # the view will fall and rotate - a good 'cancel button effect'
|
697
702
|
```
|
698
703
|
|
699
704
|
Using the completed callback you can string animations together for a low-tech
|
data/app/app_delegate.rb
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
include SugarCube::CoreGraphics
|
2
2
|
|
3
3
|
class AppDelegate
|
4
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
5
|
+
return true if RUBYMOTION_ENV == 'test'
|
6
|
+
|
7
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
8
|
+
ctlr = MyController.new
|
9
|
+
@window.rootViewController = ctlr
|
10
|
+
@window.makeKeyAndVisible
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
class MyController < UIViewController
|
16
|
+
|
17
|
+
def loadView
|
18
|
+
super.tap do
|
19
|
+
@label = 'Hi!'.uilabel
|
20
|
+
@label.center = self.view.center
|
21
|
+
@label.textColor = :white.uicolor
|
22
|
+
self.view << @label
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
4
26
|
end
|
@@ -97,9 +97,14 @@ module SugarCube
|
|
97
97
|
x_or_origin = SugarCube::CoreGraphics::Point(x_or_origin) unless x_or_origin.is_a? CGPoint
|
98
98
|
x = x_or_origin.x
|
99
99
|
y = x_or_origin.y
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
if y_or_size.is_a?(CGPoint)
|
101
|
+
w = y_or_size.x - x
|
102
|
+
h = y_or_size.y - y
|
103
|
+
else
|
104
|
+
y_or_size = SugarCube::CoreGraphics::Size(y_or_size)
|
105
|
+
w = y_or_size.width
|
106
|
+
h = y_or_size.height
|
107
|
+
end
|
103
108
|
# three args
|
104
109
|
elsif h.nil?
|
105
110
|
if x_or_origin.is_a? Numeric
|
data/lib/sugarcube/nsstring.rb
CHANGED
@@ -38,6 +38,19 @@ class NSString
|
|
38
38
|
self.uiimage.uicolor(alpha)
|
39
39
|
end
|
40
40
|
|
41
|
+
# @param font [UIFont] Optional, defaults to UIFont.systemFontOfSize(UIFont.systemFontSize)
|
42
|
+
# @return [UILabel]
|
43
|
+
def uilabel(font=nil)
|
44
|
+
font ||= :system.uifont(:label.uifontsize)
|
45
|
+
size = self.sizeWithFont(font)
|
46
|
+
UILabel.alloc.initWithFrame([[0, 0], size]).tap { |label|
|
47
|
+
label.text = self
|
48
|
+
label.font = font
|
49
|
+
# why isn't this just the default!?
|
50
|
+
label.backgroundColor = :clear.uicolor
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
41
54
|
def escape_url
|
42
55
|
CFURLCreateStringByAddingPercentEscapes(
|
43
56
|
nil,
|
data/lib/sugarcube/symbol.rb
CHANGED
@@ -670,9 +670,9 @@ class Symbol
|
|
670
670
|
end
|
671
671
|
|
672
672
|
def uifontsize
|
673
|
-
size = look_in(Symbol.
|
673
|
+
size = look_in(Symbol.font_sizes)
|
674
674
|
if size.is_a? Symbol
|
675
|
-
return UIFont.send(
|
675
|
+
return UIFont.send(size)
|
676
676
|
end
|
677
677
|
return size.to_f
|
678
678
|
end
|
data/lib/sugarcube/uiview.rb
CHANGED
@@ -115,7 +115,7 @@ class UIView
|
|
115
115
|
options = { opacity: options }
|
116
116
|
end
|
117
117
|
|
118
|
-
options[:after]
|
118
|
+
options[:after] = after
|
119
119
|
|
120
120
|
animate(options) {
|
121
121
|
self.layer.opacity = options[:opacity]
|
@@ -169,7 +169,7 @@ class UIView
|
|
169
169
|
options = { duration: options }
|
170
170
|
end
|
171
171
|
|
172
|
-
options[:after]
|
172
|
+
options[:after] = after
|
173
173
|
|
174
174
|
animate(options) {
|
175
175
|
f = self.frame
|
@@ -192,7 +192,7 @@ class UIView
|
|
192
192
|
options = { angle: options }
|
193
193
|
end
|
194
194
|
|
195
|
-
options[:after]
|
195
|
+
options[:after] = after
|
196
196
|
|
197
197
|
animate(options) {
|
198
198
|
self.transform = CGAffineTransformMakeRotation(options[:angle])
|
@@ -223,6 +223,12 @@ class UIView
|
|
223
223
|
self
|
224
224
|
end
|
225
225
|
|
226
|
+
# Vibrates the target. You can trick this thing out to do other effects, like:
|
227
|
+
# @example
|
228
|
+
# # wiggle
|
229
|
+
# view.shake(offset: 0.1, repeat: 2, duration: 0.5, keypath: 'transform.rotation')
|
230
|
+
# # slow nodding
|
231
|
+
# view.shake(offset: 20, repeat: 10, duration: 5, keypath: 'transform.translation.y')
|
226
232
|
def shake(options={})
|
227
233
|
if options.is_a? Numeric
|
228
234
|
duration = options
|
@@ -253,6 +259,46 @@ class UIView
|
|
253
259
|
self
|
254
260
|
end
|
255
261
|
|
262
|
+
# Moves the view off screen while slowly rotating it.
|
263
|
+
#
|
264
|
+
# Based on https://github.com/warrenm/AHAlertView/blob/master/AHAlertView/AHAlertView.m
|
265
|
+
def tumble(options={}, &after)
|
266
|
+
if options.is_a? Numeric
|
267
|
+
default_duration = options
|
268
|
+
options = {}
|
269
|
+
else
|
270
|
+
default_duration = 0.3
|
271
|
+
end
|
272
|
+
|
273
|
+
options[:duration] ||= default_duration
|
274
|
+
options[:options] ||= UIViewAnimationOptionCurveEaseIn
|
275
|
+
reset_transform = self.transform
|
276
|
+
reset_after = ->(finished) {
|
277
|
+
self.transform = reset_transform
|
278
|
+
}
|
279
|
+
|
280
|
+
if after
|
281
|
+
options[:after] = ->(finished) {
|
282
|
+
reset_after.call(finished)
|
283
|
+
|
284
|
+
if after.arity == 0
|
285
|
+
after.call
|
286
|
+
else
|
287
|
+
after.call(finished)
|
288
|
+
end
|
289
|
+
}
|
290
|
+
else
|
291
|
+
options[:after] = reset_after
|
292
|
+
end
|
293
|
+
|
294
|
+
self.animate(options) {
|
295
|
+
offset = CGPoint.new(0, self.superview.bounds.size.height * 1.5)
|
296
|
+
offset = CGPointApplyAffineTransform(offset, self.transform)
|
297
|
+
self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeRotation(-Math::PI/4))
|
298
|
+
self.center = CGPointMake(self.center.x + offset.x, self.center.y + offset.y)
|
299
|
+
}
|
300
|
+
end
|
301
|
+
|
256
302
|
# Easily take a snapshot of a UIView
|
257
303
|
def uiimage
|
258
304
|
scale = UIScreen.mainScreen.scale
|
data/lib/sugarcube/version.rb
CHANGED
data/spec/core_graphics_spec.rb
CHANGED
@@ -135,7 +135,7 @@ describe "SugarCube::CoreGraphics" do
|
|
135
135
|
CGRectEqualToRect(r, CGRect.new([array[0], array[1]], [array[2], array[3]])).should == true
|
136
136
|
end
|
137
137
|
|
138
|
-
it 'should accept 2 arguments (CGPoint, CGSize)' do
|
138
|
+
it 'should accept 2 arguments: (CGPoint, CGSize)' do
|
139
139
|
args = [CGPoint.new(1, 2), CGSize.new(3, 4)]
|
140
140
|
r = Rect(*args)
|
141
141
|
r.origin.x.should == 1
|
@@ -145,14 +145,14 @@ describe "SugarCube::CoreGraphics" do
|
|
145
145
|
CGRectEqualToRect(r, CGRect.new(args[0], args[1])).should == true
|
146
146
|
end
|
147
147
|
|
148
|
-
it 'should accept 2 arguments: (CGPoint,
|
149
|
-
args = [CGPoint.new(1, 2),
|
148
|
+
it 'should accept 2 arguments: (CGPoint, CGPoint)' do
|
149
|
+
args = [CGPoint.new(1, 2), CGPoint.new(3, 4)]
|
150
150
|
r = Rect(*args)
|
151
151
|
r.origin.x.should == 1
|
152
152
|
r.origin.y.should == 2
|
153
|
-
r.size.width.should ==
|
154
|
-
r.size.height.should ==
|
155
|
-
CGRectEqualToRect(r, CGRect.new(args[0],
|
153
|
+
r.size.width.should == 2
|
154
|
+
r.size.height.should == 2
|
155
|
+
CGRectEqualToRect(r, CGRect.new(args[0], [2, 2])).should == true
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should accept 3 arguments: ([x, y], w, h)' do
|
data/spec/nsstring_spec.rb
CHANGED
@@ -48,6 +48,26 @@ describe "NSString" do
|
|
48
48
|
((color.blue * 2).round / 2.0).should == 0.5
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should have a #uilabel method" do
|
52
|
+
str = 'test'
|
53
|
+
str_size = str.sizeWithFont(UIFont.systemFontOfSize(UIFont.labelFontSize))
|
54
|
+
label = str.uilabel
|
55
|
+
label.size.width == str_size.width
|
56
|
+
label.size.height == str_size.height
|
57
|
+
label.backgroundColor == UIColor.clearColor
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have a #uilabel(font) method" do
|
61
|
+
str = 'test'
|
62
|
+
font = UIFont.boldSystemFontOfSize(20)
|
63
|
+
str_size = str.sizeWithFont(font)
|
64
|
+
label = str.uilabel(font)
|
65
|
+
label.font.should == font
|
66
|
+
label.size.width == str_size.width
|
67
|
+
label.size.height == str_size.height
|
68
|
+
label.backgroundColor == UIColor.clearColor
|
69
|
+
end
|
70
|
+
|
51
71
|
it "should have a #escape_url method" do
|
52
72
|
' '.escape_url.should == '%20'
|
53
73
|
'?<>&=;%'.escape_url.should == '%3F%3C%3E%26%3D%3B%25'
|
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.16.
|
4
|
+
version: 0.16.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-02-
|
16
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: ! '== Description
|
19
19
|
|