sugarcube 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -45,6 +45,13 @@ Installation
45
45
  Examples
46
46
  ========
47
47
 
48
+ Array
49
+ -------
50
+
51
+ ```ruby
52
+ [1, 3].uiindexpath # NSIndexPath.indexPathWithIndex(1).indexPathByAddingIndex(3)
53
+ ```
54
+
48
55
  Fixnum
49
56
  --------
50
57
 
@@ -119,6 +126,7 @@ This is the "big daddy". Lots of sugar here...
119
126
  :rounded.uibuttontype # => UIButtonTypeRoundedRect
120
127
  :highlighted.uicontrolstate # => UIControlStateHighlighted
121
128
  :touch.uicontrolevent # => UIControlEventTouchUpInside
129
+ :changed.uicontrolevent # => UIControlEventValueChanged
122
130
  :all.uicontrolevent # => UIControlEventAllEvents
123
131
  :blue.uicolor # UIColor.blueColor
124
132
  # all CSS colors are supported, and alpha
@@ -130,6 +138,7 @@ This is the "big daddy". Lots of sugar here...
130
138
  :small.uifont # => UIFont.systemFontOfSize(:small.uifontsize)
131
139
  :bold.uifont(:small) # UIFont.boldSystemFontOfSize(:small.uifontsize)
132
140
  :large.uiactivityindicatorstyle # :large, :white, :gray
141
+ :bar.uisegmentedstyle # :plain, :bordered, :bar, :bezeled
133
142
 
134
143
  # UITableView and UITableViewCell have LOTS of associated constants... I'm
135
144
  # adding them as I come across them.
@@ -214,7 +223,9 @@ view.shake offset: 20, repeat: 10, duration: 5, keypath: 'transform.translation.
214
223
  superview.shake offset: 0.1, repeat: 2, duration: 0.5, keypath: 'transform.rotation'
215
224
  ```
216
225
 
217
- ###### View factories
226
+ ##### View factories
227
+
228
+ ###### UIButton
218
229
 
219
230
  ```ruby
220
231
  UIButton.buttonWithType(:custom.uibuttontype)
@@ -233,6 +244,8 @@ UIButton.contact => UIButton.buttonWithType(:contact.uibuttontype)
233
244
  UIButton.contact_add => UIButton.buttonWithType(:contact_add.uibuttontype)
234
245
  ```
235
246
 
247
+ ###### UITableView
248
+
236
249
  ```ruby
237
250
  UITableView.alloc.initWithFrame([[0, 0], [320, 480]], style: :plain.uitableviewstyle)
238
251
  # custom frame:
@@ -243,6 +256,17 @@ UITableView.alloc.initWithFrame([[0, 0], [320, 400]], style: :grouped.uitablevie
243
256
  UITableView.plain
244
257
  # custom frame:
245
258
  UITableView.grouped([[0, 0], [320, 400]])
259
+ ```
260
+
261
+ ###### UISegmentedControle
262
+
263
+ ```ruby
264
+ control = UISegmentedControl.alloc.initItems(["one", "ah-two-whoo", "thr-r-r-ree"])
265
+ control.segmentedControlStyle = :bar.uisegmentedstyle
266
+
267
+ # =>
268
+
269
+ UISegmentedControl.bar(["one", "ah-two-whoo", "thr-r-r-ree"])
246
270
  ```
247
271
 
248
272
  UIControl
@@ -190,8 +190,7 @@ module SugarCube
190
190
  print " "
191
191
  elsif views_index < 100
192
192
  print " "
193
- elsif views_index > 999
194
- # good god, man!
193
+ elsif views_index > 999 # good god, man!
195
194
  space = ''
196
195
  end
197
196
  print views_index.to_s + ":" + space
@@ -204,7 +203,7 @@ module SugarCube
204
203
  print ". "
205
204
  tab = ""
206
205
  end
207
- puts view.inspect
206
+ puts "#{view.class.name}(##{view.object_id}, #{view.frame.to_s})"
208
207
 
209
208
  view.subviews.each_index {|index|
210
209
  subview = view.subviews[index]
@@ -8,4 +8,20 @@ class Array
8
8
  ret
9
9
  end
10
10
 
11
+ def uiindexpath
12
+ if self.length == 0
13
+ raise "An index path must have at least one index"
14
+ end
15
+
16
+ path = nil
17
+ self.each do |val|
18
+ if path
19
+ path = path.indexPathByAddingIndex(val)
20
+ else
21
+ path = NSIndexPath.indexPathWithIndex(val)
22
+ end
23
+ end
24
+ return path
25
+ end
26
+
11
27
  end
@@ -25,27 +25,32 @@ You can extend the defaults by adding entries:
25
25
  class Symbol
26
26
  class << self
27
27
  attr_accessor :devices
28
+ attr_accessor :orientations
29
+ attr_accessor :returnkeys
30
+ attr_accessor :statusbar_styles
31
+ attr_accessor :barmetrics
32
+ attr_accessor :barbuttomitems
33
+ attr_accessor :keyboardtypes
34
+
28
35
  attr_accessor :textalignments
29
36
  attr_accessor :linebreakmodes
30
37
  attr_accessor :baselineadjustments
31
- attr_accessor :orientations
38
+ attr_accessor :system_fonts
39
+ attr_accessor :font_sizes
40
+
32
41
  attr_accessor :buttontypes
33
42
  attr_accessor :bordertypes
34
43
  attr_accessor :controlstates
35
44
  attr_accessor :controlevents
36
- attr_accessor :system_fonts
37
- attr_accessor :font_sizes
38
- attr_accessor :returnkeys
39
45
  attr_accessor :activityindicator_styles
46
+ attr_accessor :segmented_styles
47
+ attr_accessor :datepicker_modes
48
+
40
49
  attr_accessor :tableview_styles
41
50
  attr_accessor :tableview_rowanimation
42
51
  attr_accessor :tableview_cellstyles
43
52
  attr_accessor :tableview_cellaccessorytype
44
53
  attr_accessor :tableview_cellselectionstyle
45
- attr_accessor :statusbar_styles
46
- attr_accessor :barmetrics
47
- attr_accessor :barbuttomitems
48
- attr_accessor :keyboardtypes
49
54
  end
50
55
 
51
56
  @devices = {
@@ -114,6 +119,7 @@ class Symbol
114
119
  touch: UIControlEventTouchUpInside,
115
120
  touch_up: UIControlEventTouchUpInside,
116
121
  touch_down: UIControlEventTouchDown,
122
+ changed: UIControlEventValueChanged,
117
123
 
118
124
  touch_down_repeat: UIControlEventTouchDownRepeat,
119
125
  touch_drag_inside: UIControlEventTouchDragInside,
@@ -172,6 +178,20 @@ class Symbol
172
178
  gray: UIActivityIndicatorViewStyleGray,
173
179
  }
174
180
 
181
+ @segmented_styles = {
182
+ plain: UISegmentedControlStylePlain,
183
+ bordered: UISegmentedControlStyleBordered,
184
+ bar: UISegmentedControlStyleBar,
185
+ bezeled: UISegmentedControlStyleBezeled,
186
+ }
187
+
188
+ @datepicker_modes = {
189
+ time: UIDatePickerModeTime,
190
+ date: UIDatePickerModeDate,
191
+ dateandtime: UIDatePickerModeDateAndTime,
192
+ countdowntimer: UIDatePickerModeCountDownTimer
193
+ }
194
+
175
195
  @tableview_styles = {
176
196
  plain: UITableViewStylePlain,
177
197
  grouped: UITableViewStyleGrouped,
@@ -314,6 +334,15 @@ class Symbol
314
334
  end
315
335
  alias :uiactivityindicatorviewstyle :uiactivityindicatorstyle
316
336
 
337
+ def uisegmentedstyle
338
+ look_in(Symbol.segmented_styles)
339
+ end
340
+ alias :uisegmentedcontrolstyle :uisegmentedstyle
341
+
342
+ def uidatepickermode
343
+ look_in(Symbol.datepicker_modes)
344
+ end
345
+
317
346
  def uitablestyle
318
347
  look_in(Symbol.tableview_styles)
319
348
  end
@@ -0,0 +1,9 @@
1
+ class UIPickerView
2
+ def [] index
3
+ self.selectedRowInComponent(index)
4
+ end
5
+
6
+ def []= index, value
7
+ self.selectRow(value, inComponent:index, animated:true)
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ class UISegmentedControl
2
+ class << self
3
+ def plain(items)
4
+ ret = self.alloc.initWithItems(items)
5
+ ret.segmentedControlStyle = :plain.uisegmentedstyle
6
+ ret
7
+ end
8
+
9
+ def bordered(items)
10
+ ret = self.alloc.initWithItems(items)
11
+ ret.segmentedControlStyle = :bordered.uisegmentedstyle
12
+ ret
13
+ end
14
+
15
+ def bar(items)
16
+ ret = self.alloc.initWithItems(items)
17
+ ret.segmentedControlStyle = :bar.uisegmentedstyle
18
+ ret
19
+ end
20
+
21
+ def bezeled(items)
22
+ ret = self.alloc.initWithItems(items)
23
+ ret.segmentedControlStyle = :bezeled.uisegmentedstyle
24
+ ret
25
+ end
26
+ end
27
+ end
@@ -42,6 +42,12 @@ class UIView
42
42
  options: options[:options] || UIViewAnimationOptionCurveLinear,
43
43
  animations: proc{
44
44
  self.layer.opacity = options[:opacity] || 0
45
+
46
+ if assign = options[:assign]
47
+ assign.each_pair do |key, value|
48
+ self.send("#{key}=", value)
49
+ end
50
+ end
45
51
  }, completion:after
46
52
  )
47
53
  self
@@ -76,6 +82,12 @@ class UIView
76
82
  f = self.frame
77
83
  f.origin = SugarCube::CoreGraphics::Point(position)
78
84
  self.frame = f
85
+
86
+ if assign = options[:assign]
87
+ assign.each_pair do |key, value|
88
+ self.send("#{key}=", value)
89
+ end
90
+ end
79
91
  }, completion:after
80
92
  )
81
93
  self
@@ -90,16 +102,23 @@ class UIView
90
102
  end
91
103
 
92
104
  def slide(direction, options={}, &after)
93
- size = UIScreen.mainScreen.bounds.size
105
+ if options.is_a? Numeric
106
+ options = {size: options}
107
+ end
108
+
94
109
  case direction
95
110
  when :left
96
- delta_to([-size.width, 0], options, &after)
111
+ size = options[:size] || UIScreen.mainScreen.bounds.size.width
112
+ delta_to([-size, 0], options, &after)
97
113
  when :right
98
- delta_to([+size.width, 0], options, &after)
114
+ size = options[:size] || UIScreen.mainScreen.bounds.size.width
115
+ delta_to([+size, 0], options, &after)
99
116
  when :up
100
- delta_to([0, -size.height], options, &after)
117
+ size = options[:size] || UIScreen.mainScreen.bounds.size.height
118
+ delta_to([0, -size], options, &after)
101
119
  when :down
102
- delta_to([0, +size.height], options, &after)
120
+ size = options[:size] || UIScreen.mainScreen.bounds.size.height
121
+ delta_to([0, +size], options, &after)
103
122
  else
104
123
  raise "Unknown direction #{direction.inspect}"
105
124
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.7.2'
2
+ Version = '0.7.3'
3
3
  end
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.7.2
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-25 00:00:00.000000000 Z
13
+ date: 2012-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -97,6 +97,8 @@ files:
97
97
  - lib/sugarcube/uicontrol.rb
98
98
  - lib/sugarcube/uifont.rb
99
99
  - lib/sugarcube/uiimage.rb
100
+ - lib/sugarcube/uipickerview.rb
101
+ - lib/sugarcube/uisegmentedcontrol.rb
100
102
  - lib/sugarcube/uitableview.rb
101
103
  - lib/sugarcube/uiview.rb
102
104
  - lib/sugarcube/uiviewcontroller.rb