sugarcube 0.20.25 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/Gemfile +3 -1
  2. data/Gemfile.lock +1 -1
  3. data/README.md +897 -1306
  4. data/Rakefile +3 -7
  5. data/app/uicontrol_controller.rb +2 -2
  6. data/lib/sugarcube-568.rb +1 -9
  7. data/lib/sugarcube-all.rb +18 -0
  8. data/lib/sugarcube-animations.rb +15 -0
  9. data/lib/{sugarcube → sugarcube-animations}/animation_chain.rb +0 -0
  10. data/lib/{sugarcube → sugarcube-animations}/uiview.rb +41 -111
  11. data/lib/sugarcube-anonymous.rb +1 -9
  12. data/lib/sugarcube-attributedstring.rb +1 -9
  13. data/lib/sugarcube-attributedstring/nsattributedstring.rb +2 -11
  14. data/lib/sugarcube-awesome.rb +15 -0
  15. data/lib/sugarcube-awesome/awesome_exts.rb +22 -0
  16. data/lib/sugarcube-classic.rb +26 -0
  17. data/lib/sugarcube-color.rb +15 -0
  18. data/lib/sugarcube-color/fixnum.rb +18 -0
  19. data/lib/sugarcube-color/nsarray.rb +11 -0
  20. data/lib/sugarcube-color/nsstring.rb +16 -0
  21. data/lib/{sugarcube/symbol/symbol_uicolor.rb → sugarcube-color/symbol.rb} +12 -4
  22. data/lib/{sugarcube → sugarcube-color}/uicolor.rb +16 -2
  23. data/lib/sugarcube-color/uiimage.rb +13 -0
  24. data/lib/sugarcube-common.rb +22 -0
  25. data/lib/sugarcube-constants.rb +15 -0
  26. data/lib/sugarcube-constants/symbol.rb +759 -0
  27. data/lib/sugarcube-coregraphics.rb +15 -0
  28. data/lib/{sugarcube → sugarcube-coregraphics}/core_graphics.rb +0 -0
  29. data/lib/sugarcube-corelocation.rb +17 -0
  30. data/lib/{sugarcube → sugarcube-corelocation}/core_location.rb +0 -0
  31. data/lib/sugarcube-events.rb +15 -0
  32. data/lib/{sugarcube → sugarcube-events}/uicontrol.rb +3 -3
  33. data/lib/{sugarcube → sugarcube-events}/uitextview.rb +0 -0
  34. data/lib/sugarcube-factories.rb +15 -0
  35. data/lib/{sugarcube → sugarcube-factories}/nserror.rb +0 -0
  36. data/lib/{sugarcube → sugarcube-factories}/uiactionsheet.rb +3 -1
  37. data/lib/sugarcube-factories/uiactivityindicator.rb +17 -0
  38. data/lib/{sugarcube → sugarcube-factories}/uialertview.rb +3 -3
  39. data/lib/{sugarcube → sugarcube-factories}/uibarbuttonitem.rb +19 -3
  40. data/lib/{sugarcube → sugarcube-factories}/uibutton.rb +10 -10
  41. data/lib/{sugarcube → sugarcube-factories}/uisegmentedcontrol.rb +4 -4
  42. data/lib/{sugarcube → sugarcube-factories}/uitableview.rb +0 -0
  43. data/lib/{sugarcube → sugarcube-factories}/uitableviewcell.rb +3 -7
  44. data/lib/sugarcube-files.rb +15 -0
  45. data/lib/{sugarcube/nsstring_files.rb → sugarcube-files/nsstring.rb} +0 -0
  46. data/lib/sugarcube-foundation.rb +15 -0
  47. data/lib/{sugarcube → sugarcube-foundation}/nsarray.rb +0 -18
  48. data/lib/sugarcube-foundation/nsindexpath.rb +13 -0
  49. data/lib/{sugarcube → sugarcube-foundation}/nsindexset.rb +0 -0
  50. data/lib/sugarcube-foundation/nsstring.rb +31 -0
  51. data/lib/{sugarcube → sugarcube-foundation}/nsurl.rb +0 -4
  52. data/lib/sugarcube-gestures.rb +1 -9
  53. data/lib/sugarcube-image.rb +15 -0
  54. data/lib/sugarcube-image/cicolor.rb +7 -0
  55. data/lib/sugarcube-image/cifilter.rb +772 -0
  56. data/lib/sugarcube-image/ciimage.rb +22 -0
  57. data/lib/sugarcube-image/uicolor.rb +7 -0
  58. data/lib/{sugarcube → sugarcube-image}/uiimage.rb +38 -41
  59. data/lib/sugarcube-indexpath.rb +15 -0
  60. data/lib/{sugarcube/nsindexpath.rb → sugarcube-indexpath/indexpath.rb} +12 -21
  61. data/lib/sugarcube-legacy.rb +15 -0
  62. data/lib/{sugarcube → sugarcube-legacy}/activesupport.rb +0 -0
  63. data/lib/sugarcube-legacy/log.rb +45 -0
  64. data/lib/sugarcube-legacy/symbol.rb +219 -0
  65. data/lib/sugarcube-localized.rb +15 -0
  66. data/lib/sugarcube-localized/nserror.rb +8 -0
  67. data/lib/sugarcube-localized/nsstring.rb +10 -0
  68. data/lib/sugarcube-modal.rb +15 -0
  69. data/lib/{sugarcube → sugarcube-modal}/modal.rb +0 -0
  70. data/lib/sugarcube-notifications.rb +15 -0
  71. data/lib/{sugarcube → sugarcube-notifications}/notifications.rb +0 -0
  72. data/lib/sugarcube-nscoder.rb +15 -0
  73. data/lib/{sugarcube → sugarcube-nscoder}/nscoder.rb +0 -0
  74. data/lib/sugarcube-nsdata.rb +15 -0
  75. data/lib/{sugarcube → sugarcube-nsdata}/nsdata.rb +0 -0
  76. data/lib/sugarcube-nsdata/nsstring.rb +9 -0
  77. data/lib/sugarcube-nsdata/nsurl.rb +7 -0
  78. data/lib/sugarcube-nsdata/uiimage.rb +8 -0
  79. data/lib/sugarcube-nsdate.rb +15 -0
  80. data/lib/{sugarcube → sugarcube-nsdate}/date_parser.rb +0 -0
  81. data/lib/sugarcube-nsdate/fixnum.rb +23 -0
  82. data/lib/{sugarcube → sugarcube-nsdate}/nsdate.rb +6 -1
  83. data/lib/{sugarcube → sugarcube-nsdate}/nsdate_delta.rb +0 -0
  84. data/lib/sugarcube-nsdate/nsstring.rb +16 -0
  85. data/lib/sugarcube-nsuserdefaults.rb +15 -0
  86. data/lib/{sugarcube → sugarcube-nsuserdefaults}/nsuserdefaults.rb +0 -0
  87. data/lib/sugarcube-numbers.rb +15 -0
  88. data/lib/sugarcube-numbers/fixnum.rb +25 -0
  89. data/lib/sugarcube-numbers/nsstring.rb +13 -0
  90. data/lib/{sugarcube → sugarcube-numbers}/numeric.rb +44 -4
  91. data/lib/sugarcube-osx/adjust.rb +373 -0
  92. data/lib/sugarcube-pipes.rb +15 -0
  93. data/lib/sugarcube-pipes/pipes.rb +78 -0
  94. data/lib/sugarcube-pointer.rb +15 -0
  95. data/lib/sugarcube-pointer/nsarray.rb +13 -0
  96. data/lib/sugarcube-repl.rb +1 -9
  97. data/lib/sugarcube-resources.rb +15 -0
  98. data/lib/sugarcube-timer.rb +15 -0
  99. data/lib/{sugarcube → sugarcube-timer}/timer.rb +0 -0
  100. data/lib/sugarcube-to_s.rb +15 -0
  101. data/lib/{sugarcube/to_s → sugarcube-to_s}/nserror.rb +1 -4
  102. data/lib/sugarcube-to_s/nsindexpath.rb +7 -0
  103. data/lib/{sugarcube/to_s → sugarcube-to_s}/nslayoutconstraint.rb +0 -0
  104. data/lib/{sugarcube/to_s → sugarcube-to_s}/nsnotification.rb +0 -0
  105. data/lib/{sugarcube/to_s → sugarcube-to_s}/nsset.rb +0 -0
  106. data/lib/{sugarcube/to_s → sugarcube-to_s}/nsurl.rb +0 -0
  107. data/lib/{sugarcube/to_s → sugarcube-to_s}/uicolor.rb +0 -0
  108. data/lib/{sugarcube/to_s → sugarcube-to_s}/uievent.rb +0 -0
  109. data/lib/{sugarcube/to_s → sugarcube-to_s}/uilabel.rb +0 -0
  110. data/lib/{sugarcube/to_s → sugarcube-to_s}/uitextfield.rb +0 -0
  111. data/lib/{sugarcube/to_s → sugarcube-to_s}/uitouch.rb +0 -0
  112. data/lib/{sugarcube/to_s → sugarcube-to_s}/uiview.rb +0 -0
  113. data/lib/{sugarcube/to_s → sugarcube-to_s}/uiviewcontroller.rb +0 -0
  114. data/lib/sugarcube-uicolor.rb +1 -0
  115. data/lib/sugarcube-uifont.rb +15 -0
  116. data/lib/sugarcube-uiimage.rb +1 -0
  117. data/lib/sugarcube-uikit.rb +15 -0
  118. data/lib/{sugarcube → sugarcube-uikit}/calayer.rb +0 -0
  119. data/lib/sugarcube-uikit/nsattributedstring.rb +12 -0
  120. data/lib/sugarcube-uikit/nsstring.rb +38 -0
  121. data/lib/sugarcube-uikit/symbol.rb +67 -0
  122. data/lib/{sugarcube → sugarcube-uikit}/uifont.rb +1 -4
  123. data/lib/sugarcube-uikit/uiimage.rb +9 -0
  124. data/lib/{sugarcube → sugarcube-uikit}/uilabel.rb +0 -0
  125. data/lib/{sugarcube → sugarcube-uikit}/uipickerview.rb +0 -0
  126. data/lib/sugarcube-uikit/uiview.rb +100 -0
  127. data/lib/{sugarcube → sugarcube-uikit}/uiviewcontroller.rb +0 -0
  128. data/lib/{sugarcube → sugarcube-uikit}/uiwebview.rb +0 -0
  129. data/lib/sugarcube-unholy.rb +1 -9
  130. data/lib/sugarcube.rb +4 -9
  131. data/lib/sugarcube/adjust.rb +1 -0
  132. data/lib/sugarcube/look_in.rb +22 -0
  133. data/lib/sugarcube/version.rb +1 -1
  134. data/runtests +1 -1
  135. data/spec/{uicolor_components_spec.rb → color_components_spec.rb} +0 -0
  136. data/spec/{uicolor_other_representations_spec.rb → color_other_representations_spec.rb} +0 -0
  137. data/spec/{uicolor_spec.rb → color_spec.rb} +0 -0
  138. data/spec/image_cifilters_spec.rb +549 -0
  139. data/spec/{uiimage_color_at_spec.rb → image_color_at_spec.rb} +0 -0
  140. data/spec/{uiimage_scale_spec.rb → image_scale_spec.rb} +0 -0
  141. data/spec/image_uiimage_filters_spec.rb +47 -0
  142. data/spec/nsdate_spec.rb +11 -0
  143. data/spec/nsurl_spec.rb +1 -1
  144. data/spec/numeric_spec.rb +10 -0
  145. data/spec/pipes_spec.rb +135 -0
  146. data/spec/sugarcube_legacy.rb +59 -0
  147. data/spec/symbol_constants_spec.rb +809 -0
  148. data/spec/symbol_uicolor_spec.rb +20 -4
  149. data/spec/symbol_uifont_spec.rb +30 -0
  150. data/spec/uiactionsheet_spec.rb +1 -1
  151. data/spec/uialertview_spec.rb +1 -1
  152. data/spec/uibarbuttonitem_spec.rb +46 -46
  153. data/sugarcube.gemspec +1 -1
  154. metadata +142 -74
  155. data/lib/sugarcube/exceptions.rb +0 -2
  156. data/lib/sugarcube/fixnum.rb +0 -59
  157. data/lib/sugarcube/nsstring.rb +0 -107
  158. data/lib/sugarcube/symbol.rb +0 -766
  159. data/lib/sugarcube/uiactivityindicator.rb +0 -17
  160. data/lib/sugarcube/uuid.rb +0 -10
  161. data/spec/activesupport_spec.rb +0 -96
  162. data/spec/symbol_spec.rb +0 -32
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-pipes/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
@@ -0,0 +1,78 @@
1
+ class UIImage
2
+
3
+ # Operator shorthand for `apply_filter`, or coerces the image into other
4
+ # formats.
5
+ #
6
+ # @example
7
+ # image = 'test'.uiimage
8
+ # new_image = image | CIFilter.gaussian_blur # => returns a CIImage
9
+ # new_image = (image | CIFilter.gaussian_blur).uiimage # => coerce to UIImage
10
+ # new_image = image | CIFilter.gaussian_blur | UIImage # => coerce to UIImage via chaining
11
+ def |(filter)
12
+ if CIFilter === filter
13
+ apply_filter(filter)
14
+ elsif filter == UIImage
15
+ self
16
+ elsif filter == UIView || filter == UIImageView
17
+ self.uiimageview
18
+ elsif filter == CIImage
19
+ ciimage
20
+ elsif filter == UIColor
21
+ uicolor
22
+ elsif filter == NSData
23
+ nsdata
24
+ else
25
+ raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+
32
+ class UIView
33
+
34
+ # Applies a filter (to a UIImage representation) or coerces to another format
35
+ def |(filter)
36
+ if filter == UIImage
37
+ self.uiimage
38
+ else
39
+ raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+
46
+ class CIImage
47
+
48
+ def |(filter)
49
+ if CIFilter === filter
50
+ apply_filter(filter)
51
+ elsif filter == UIImage
52
+ self.uiimage
53
+ elsif filter == UIView || filter == UIImageView
54
+ self.uiimage.uiimageview
55
+ elsif filter == CIImage
56
+ self
57
+ else
58
+ raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+
65
+ class String
66
+
67
+ def |(filter)
68
+ if Regexp === filter
69
+ match = filter.match(self)
70
+ match && match[0]
71
+ elsif String === filter
72
+ self.index(filter) && filter
73
+ else
74
+ raise "The `|` operator is not supported for the #{filter.is_a?(Class) ? filter.name : filter.class.name} class"
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-pointer/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class NSArray
2
+
3
+ # @param type [Symbol] type A pointer type from the list at {http://www.rubymotion.com/developer-center/guides/runtime/ RubyMotion Pointers Reference#_pointers}
4
+ # @return [Pointer] A pointer to the array, of the specified type
5
+ def to_pointer(type)
6
+ ret = Pointer.new(type, self.length)
7
+ self.each_index do |i|
8
+ ret[i] = self[i]
9
+ end
10
+ ret
11
+ end
12
+
13
+ end
@@ -7,15 +7,7 @@ Motion::Project::App.setup do |app|
7
7
  # scans app.files until it finds app/ (the default)
8
8
  # if found, it inserts just before those files, otherwise it will insert to
9
9
  # the end of the list
10
- insert_point = 0
11
- app.files.each_index do |index|
12
- file = app.files[index]
13
- if file =~ /^(?:\.\/)?app\//
14
- # found app/, so stop looking
15
- break
16
- end
17
- insert_point = index + 1
18
- end
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
19
11
 
20
12
  Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-repl/**/*.rb')).reverse.each do |file|
21
13
  app.files.insert(insert_point, file)
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-resources/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-timer/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
File without changes
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-to_s/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
@@ -1,8 +1,4 @@
1
1
  class NSError
2
- def localized
3
- localizedDescription
4
- end
5
- alias _ localized
6
2
 
7
3
  def to_s
8
4
  "#<#{self.class.name}:0x#{self.object_id.to_s(16)}, "+
@@ -10,4 +6,5 @@ class NSError
10
6
  "domain=#{domain.inspect}, userInfo=#{userInfo.inspect}"+
11
7
  ">"
12
8
  end
9
+
13
10
  end
@@ -0,0 +1,7 @@
1
+ class NSIndexPath
2
+
3
+ def to_s
4
+ "<NSIndexPath #{to_a.to_s}>"
5
+ end
6
+
7
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ raise "I changed the 'sugarcube-\033[0;1muicolor\033[0m' package to 'sugarcube-\033[0;1mcolor\033[0m'."
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-uifont/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ raise "I changed the 'sugarcube-\033[0;1muiimage\033[0m' package to 'sugarcube-\033[0;1mimage\033[0m'."
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+
6
+ Motion::Project::App.setup do |app|
7
+ # scans app.files until it finds app/ (the default)
8
+ # if found, it inserts just before those files, otherwise it will insert to
9
+ # the end of the list
10
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
11
+
12
+ Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-uikit/**/*.rb')).reverse.each do |file|
13
+ app.files.insert(insert_point, file)
14
+ end
15
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ class NSAttributedString
2
+
3
+ # @return [UILabel]
4
+ def uilabel
5
+ UILabel.alloc.initWithFrame([[0, 0], [0, 0]]).tap do |label|
6
+ label.attributedText = self
7
+ label.backgroundColor = :clear.uicolor
8
+ label.sizeToFit
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,38 @@
1
+ class NSString
2
+
3
+ # @return [UIImage]
4
+ def uiimage
5
+ UIImage.imageNamed(self).tap do |retval|
6
+ NSLog("No image named #{self}") unless retval
7
+ end
8
+ end
9
+
10
+ # @return [UIFont]
11
+ def uifont(size=nil)
12
+ size ||= UIFont.systemFontSize
13
+ UIFont.fontWithName(self, size:size)
14
+ end
15
+
16
+ # @param font [UIFont] Optional, defaults to UIFont.systemFontOfSize(UIFont.systemFontSize)
17
+ # @return [UILabel]
18
+ def uilabel(font=nil)
19
+ font ||= :system.uifont(UIFont.labelFontSize)
20
+ size = self.sizeWithFont(font)
21
+ UILabel.alloc.initWithFrame([[0, 0], size]).tap { |label|
22
+ label.text = self
23
+ label.font = font
24
+ # why isn't this just the default!?
25
+ label.backgroundColor = :clear.uicolor
26
+ }
27
+ end
28
+
29
+ # @return [UIImageView]
30
+ def uiimageview
31
+ image = UIImage.imageNamed(self)
32
+ unless image
33
+ NSLog("No image named #{self}")
34
+ end
35
+ UIImageView.alloc.initWithImage(image)
36
+ end
37
+
38
+ end
@@ -0,0 +1,67 @@
1
+ =begin
2
+ Example:
3
+
4
+ # fonts
5
+ :system.uifont => UIFont.systemFontOfSize(UIFont.systemFontSize)
6
+ :label.uifont => UIFont.systemFontOfSize(UIFont.labelFontSize)
7
+
8
+ You can extend the defaults by adding entries:
9
+
10
+ Symbol.uifontsize[:big] = 40
11
+
12
+ :big.uifont => UIFont
13
+
14
+ =end
15
+ class Symbol
16
+
17
+ def uifont(size=nil)
18
+ size ||= UIFont.systemFontSize
19
+ # system fonts
20
+ if Symbol.uifont.has_key? self
21
+ font = SugarCube.look_in(self, Symbol.uifont)
22
+ if size.is_a?(Symbol)
23
+ size = size.uifontsize
24
+ end
25
+
26
+ if font.is_a?(Symbol)
27
+ return UIFont.send(font, size)
28
+ else
29
+ return font.uifont(size)
30
+ end
31
+ else
32
+ if size.is_a?(Symbol)
33
+ size = size.uifontsize
34
+ end
35
+ return UIFont.systemFontOfSize(size)
36
+ end
37
+ end
38
+
39
+ def uifontsize
40
+ size = SugarCube.look_in(self, Symbol.uifontsize)
41
+ if size.is_a?(Symbol)
42
+ return UIFont.send(size)
43
+ end
44
+ return size.to_f
45
+ end
46
+
47
+ class << self
48
+ attr :uifont
49
+ attr :uifontsize
50
+ end
51
+
52
+ @uifont = {
53
+ system: :"systemFontOfSize:",
54
+ bold: :"boldSystemFontOfSize:",
55
+ italic: :"italicSystemFontOfSize:",
56
+ monospace: 'Courier New',
57
+ }
58
+
59
+ @uifontsize = {
60
+ label: :labelFontSize,
61
+ button: :buttonFontSize,
62
+ small: :smallSystemFontSize,
63
+ system: :systemFontSize,
64
+ }
65
+
66
+
67
+ end
@@ -1,6 +1,3 @@
1
-
2
1
  class UIFont
3
2
  def uifont ; self ; end
4
-
5
-
6
- end
3
+ end
@@ -0,0 +1,9 @@
1
+ class UIImage
2
+ def uiimage ; self ; end
3
+
4
+ # @return [UIImageView]
5
+ def uiimageview
6
+ UIImageView.alloc.initWithImage(self)
7
+ end
8
+
9
+ end
File without changes
File without changes
@@ -0,0 +1,100 @@
1
+ class UIView
2
+
3
+ class << self
4
+
5
+ # returns the first responder, starting at the Window and searching every subview
6
+ def first_responder
7
+ UIApplication.sharedApplication.keyWindow.first_responder
8
+ end
9
+
10
+ def attr_updates(*attrs)
11
+ attr_accessor(*attrs)
12
+ attrs.each do |attr|
13
+ define_method("#{attr}=") { |value|
14
+ if instance_variable_get("@#{attr}") != value
15
+ setNeedsDisplay
16
+ end
17
+ instance_variable_set("@#{attr}", value)
18
+ }
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ # superview << view
25
+ # => superview.addSubview(view)
26
+ def <<(view)
27
+ self.addSubview(view)
28
+ return self
29
+ end
30
+
31
+ def unshift(view)
32
+ self.insertSubview(view, atIndex:0)
33
+ return self
34
+ end
35
+
36
+ # returns the first responder, or nil if it cannot be found
37
+ def first_responder
38
+ if self.firstResponder?
39
+ return self
40
+ end
41
+
42
+ found = nil
43
+ self.subviews.each do |subview|
44
+ found = subview.first_responder
45
+ break if found
46
+ end
47
+
48
+ return found
49
+ end
50
+
51
+ # returns the nearest nextResponder instance that is a UIViewController. Goes
52
+ # up the responder chain until the nextResponder is a UIViewController
53
+ # subclass, or returns nil if none is found.
54
+ def controller
55
+ if nextResponder && nextResponder.is_a?(UIViewController)
56
+ nextResponder
57
+ elsif nextResponder
58
+ nextResponder.controller
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ # Easily take a snapshot of a `UIView`.
65
+ #
66
+ # Calling `uiimage` with no arguments will return the image based on the
67
+ # `bounds` of the image. In the case of container views (notably
68
+ # `UIScrollView` and its children) this does not include the entire contents,
69
+ # which is something you probably want.
70
+ #
71
+ # If you pass a truthy value to this method, it will use the `contentSize` of
72
+ # the view instead of the `bounds`, and it will draw all the child views, not
73
+ # just those that are visible in the viewport.
74
+ #
75
+ # It is guaranteed that `true` and `:all` will always have this behavior. In
76
+ # the future, if this argument becomes something that accepts multiple values,
77
+ # those two are sacred.
78
+ def uiimage(use_content_size=false)
79
+ scale = UIScreen.mainScreen.scale
80
+ if use_content_size
81
+ UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
82
+ context = UIGraphicsGetCurrentContext()
83
+ subviews.each do |subview|
84
+ CGContextSaveGState(context)
85
+ CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
86
+ subview.layer.renderInContext(context)
87
+ CGContextRestoreGState(context)
88
+ end
89
+ image = UIGraphicsGetImageFromCurrentImageContext()
90
+ UIGraphicsEndImageContext()
91
+ else
92
+ UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
93
+ layer.renderInContext(UIGraphicsGetCurrentContext())
94
+ image = UIGraphicsGetImageFromCurrentImageContext()
95
+ UIGraphicsEndImageContext()
96
+ end
97
+ return image
98
+ end
99
+
100
+ end