sugarcube 0.20.12 → 0.20.13
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/lib/sugarcube/uicontrol.rb
CHANGED
@@ -7,7 +7,7 @@ class UIControl
|
|
7
7
|
# @example
|
8
8
|
# button = UIButton.alloc.initWithFrame([0, 0, 10, 10])
|
9
9
|
# button.on(:touch) { my_code }
|
10
|
-
# button.on(:
|
10
|
+
# button.on(:touch_up_outside, :touch_cancel) { my_code }
|
11
11
|
# # up to two arguments can be passed in
|
12
12
|
# button.on(:touch) { |sender,touch_event| my_code }
|
13
13
|
def on(*events, &block)
|
@@ -29,7 +29,7 @@ class UIControl
|
|
29
29
|
#
|
30
30
|
# @example
|
31
31
|
# button.off(:touch)
|
32
|
-
# button.off(:
|
32
|
+
# button.off(:touch_up_outside, :touch_cancel)
|
33
33
|
# button.off # all events
|
34
34
|
def off(*events)
|
35
35
|
if events.length == 0
|
@@ -47,6 +47,20 @@ class UIControl
|
|
47
47
|
self
|
48
48
|
end
|
49
49
|
|
50
|
+
# Useful during testing, or to simulate a button press.
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# button.trigger(:touch)
|
54
|
+
# button.trigger(:touch_drag_outside, :touch_drag_exits)
|
55
|
+
def trigger(*events)
|
56
|
+
event_mask = 0
|
57
|
+
events.each do |event|
|
58
|
+
event = event.uicontrolevent unless event.is_a? Fixnum
|
59
|
+
event_mask |= event
|
60
|
+
end
|
61
|
+
sendActionsForControlEvents(event_mask)
|
62
|
+
end
|
63
|
+
|
50
64
|
# private
|
51
65
|
# event blocks need to be retained, and the addTarget method explicitly does
|
52
66
|
# *not* retain `target`. This makes sure that callbacks are retained by
|
data/lib/sugarcube/version.rb
CHANGED
@@ -226,7 +226,7 @@ class NSAttributedString
|
|
226
226
|
end
|
227
227
|
|
228
228
|
def +(attributedstring)
|
229
|
-
NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring
|
229
|
+
NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring.nsattributedstring
|
230
230
|
end
|
231
231
|
|
232
232
|
end
|
data/spec/uicontrol_spec.rb
CHANGED
@@ -17,6 +17,13 @@ describe 'UIControl' do
|
|
17
17
|
controller.touched_count.should == 1
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'button1 should respond to touches using `trigger`' do
|
21
|
+
controller.button1.trigger(:touch)
|
22
|
+
controller.touched.should == controller.button1
|
23
|
+
controller.touched_1.should == true
|
24
|
+
controller.touched_count.should == 1
|
25
|
+
end
|
26
|
+
|
20
27
|
it 'button2 should respond to touches' do
|
21
28
|
controller.button2.sendActionsForControlEvents(:touch.uicontrolevent)
|
22
29
|
controller.touched.should == controller.button2
|