sugarcube 0.9.3 → 0.9.4

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 CHANGED
@@ -833,9 +833,67 @@ Assume I ran `include SugarCube::Adjust` in these examples.
833
833
 
834
834
  # if you forget what view you are adjusting, run `adjust` again
835
835
  > a
836
- => {UITextField @ x: 46.0 y:214.0, 280.0×33.0} child of UIView
836
+ => UITextField(#9ce6470, {{46, 214}, {280, 33}}, child of UIView(#10a6da20)
837
837
  ```
838
838
 
839
+ The most useful feature of the REPL adjustment is the ability to quickly
840
+ position and size your UI elements __visually__ and then paste the final values
841
+ into your code. In order to better accomodate that, `adjust` has an option to
842
+ modify the output format.
843
+
844
+ This better facilitates copy/paste of the values. Currently supported is:
845
+ * Default (RubyMotion) (`nil`, `:default`)
846
+ * Objective-C (`:objc`)
847
+ * JSON (`:json`)
848
+
849
+ #### Objective-C style
850
+
851
+ ```
852
+ (UIImageView(#8d67e00, {{0, 0},...)> tree
853
+ 0: . UIWindow(#6e27180: {{0, 0}, {320, 480}})
854
+ 1: `-- UIView(#8d631b0: {{0, 20}, {320, 460}})
855
+ 2: +-- UIButton(#6d6c090: {{10, 10}, {320, 463.401}})
856
+ 3: | `-- UIImageView(#8d67e00: {{0, 0}, {320, 463.401}})
857
+ 4: `-- UIRoundedRectButton(#8d68170: {{10, 30}, {30, 200}})
858
+ 5: `-- UIButtonLabel(#8d69c30: {{2, 90}, {26, 19}})
859
+ => UIWindow(#6e27180, {{0, 0}, {320, 480}},
860
+
861
+ # you can pass the format into the adjust method:
862
+ (UIImageView(#8d67e00, {{0, 0},...)> a 4, :objc
863
+ => "UIRoundedRectButton(#8d68170: [[10.0, 30.0], [200.0, 30.0]])"
864
+
865
+ # or you can assign repl_format explicitly (adjust does this for you when you hand it a format)
866
+ (UIImageView(#8d67e00, {{0, 0},...)> repl_format :objc
867
+ => :objc
868
+
869
+ # either way, it will continue to be used in subsequent calls
870
+ (UIImageView(#8d67e00, {{0, 0},...)> wider 15
871
+ [[10.0, 30.0], [200.0, 45.0]]
872
+ => "UIRoundedRectButton(#8d68170: [[10.0, 30.0], [200.0, 45.0]]) child of UIView(#8d631b0)"
873
+ ```
874
+
875
+ #### JSON (or GeoMotion)
876
+
877
+ ```
878
+ (UIImageView(#8d67e00, {{0, 0},...)> a 1, :json
879
+ => "UIView(#8d631b0: [x: 0.0, y: 20.0, height: 460.0, width: 320.0])"
880
+ (UIImageView(#8d67e00, {{0, 0},...)> wider 30
881
+ => "CGRect(#6e9c9f0: [x: 0.0, y: 20.0, height: 460.0, width: 350.0])"
882
+ (UIImageView(#8d67e00, {{0, 0},...)> right 130
883
+ => "CGRect(#8dc6a40: [x: 130.0, y: 20.0, height: 460.0, width: 350.0])"
884
+ (UIImageView(#8d67e00, {{0, 0},...)> tree
885
+ 0: . UIWindow(#6e27180: [x: 0.0, y: 0.0, height: 480.0, width: 320.0])
886
+ 1: `-- UIView(#8d631b0: [x: 130.0, y: 20.0, height: 460.0, width: 350.0])
887
+ 2: +-- UIButton(#6d6c090: [x: 10.0, y: 10.0, height: 463.400512695312, width: 320.0])
888
+ 3: | `-- UIImageView(#8d67e00: [x: 0.0, y: 0.0, height: 463.400512695312, width: 320.0])
889
+ 4: `-- UIRoundedRectButton(#8d68170: [x: 10.0, y: 30.0, height: 200.0, width: 45.0])
890
+ 5: `-- UIButtonLabel(#8d69c30: [x: 4.0, y: 90.0, height: 19.0, width: 37.0])
891
+ => UIWindow(#6e27180, {{0, 0}, {320, 480}},
892
+ ```
893
+
894
+ Note: The `format` parameter can be passed as either a symbol or a string
895
+
896
+
839
897
  Pointers
840
898
  ----------
841
899
 
@@ -2,8 +2,19 @@ module SugarCube
2
2
  module Adjust
3
3
  module_function
4
4
 
5
- def adjust view=nil
6
- @@sugarcube_view ||= nil
5
+ def repl_format(format=nil)
6
+ if format
7
+ @@repl_format = format
8
+ else
9
+ # if adjust has not been called, the instance variable has not yet been set
10
+ @@repl_format ||= :ruby
11
+ end
12
+ @@repl_format
13
+ end
14
+
15
+ def adjust(view=nil, format=nil)
16
+ SugarCube::Adjust::repl_format(format.to_sym) if format
17
+ @@sugarcube_view ||= nil # this looks like a NOOP, but ||= also checks whether the variable exists. aka: errors happen if we don't do this.
7
18
  return @@sugarcube_view if not view
8
19
 
9
20
  if view.is_a? Fixnum
@@ -19,6 +30,9 @@ module SugarCube
19
30
  shadow: SugarCube::Adjust.shadow,
20
31
  }
21
32
 
33
+ if format
34
+ puts format_frame view.frame
35
+ end
22
36
  view
23
37
  end
24
38
  alias a adjust
@@ -31,6 +45,9 @@ module SugarCube
31
45
  return SugarCube::CoreGraphics::Rect(@@sugarcube_view.frame) if not f
32
46
 
33
47
  @@sugarcube_view.frame = f
48
+ puts format_frame(f)
49
+
50
+ @@sugarcube_view
34
51
  end
35
52
  alias f frame
36
53
 
@@ -47,6 +64,9 @@ module SugarCube
47
64
  f = @@sugarcube_view.frame
48
65
  f.origin.x += val
49
66
  @@sugarcube_view.frame = f
67
+ puts format_frame(f)
68
+
69
+ @@sugarcube_view
50
70
  end
51
71
  alias r right
52
72
 
@@ -62,6 +82,9 @@ module SugarCube
62
82
  f = @@sugarcube_view.frame
63
83
  f.origin.y += val
64
84
  @@sugarcube_view.frame = f
85
+ puts format_frame(f)
86
+
87
+ @@sugarcube_view
65
88
  end
66
89
  alias d down
67
90
 
@@ -79,6 +102,9 @@ module SugarCube
79
102
  f.origin = x
80
103
  end
81
104
  @@sugarcube_view.frame = f
105
+ puts format_frame(f)
106
+
107
+ @@sugarcube_view
82
108
  end
83
109
  alias o origin
84
110
 
@@ -95,6 +121,9 @@ module SugarCube
95
121
  f = @@sugarcube_view.frame
96
122
  f.size.width += val
97
123
  @@sugarcube_view.frame = f
124
+ puts format_frame(f)
125
+
126
+ @@sugarcube_view
98
127
  end
99
128
  alias w wider
100
129
 
@@ -110,6 +139,9 @@ module SugarCube
110
139
  f = @@sugarcube_view.frame
111
140
  f.size.height += val
112
141
  @@sugarcube_view.frame = f
142
+ puts format_frame(f)
143
+
144
+ @@sugarcube_view
113
145
  end
114
146
  alias t taller
115
147
 
@@ -127,6 +159,9 @@ module SugarCube
127
159
  f.size = w
128
160
  end
129
161
  @@sugarcube_view.frame = f
162
+ puts format_frame(f)
163
+
164
+ @@sugarcube_view
130
165
  end
131
166
  alias z size
132
167
 
@@ -205,7 +240,7 @@ module SugarCube
205
240
  if self == view
206
241
  print "\033[1m"
207
242
  end
208
- puts "#{view.class.name}(##{view.object_id.to_s(16)}, #{view.frame.to_s})"
243
+ puts "#{view.class.name}(##{view.object_id.to_s(16)}: #{format_frame(view.frame)})"
209
244
  if self == view
210
245
  print "\033[0m"
211
246
  end
@@ -230,5 +265,16 @@ module SugarCube
230
265
  end
231
266
  end
232
267
 
268
+ def format_frame(frame)
269
+ case SugarCube::Adjust::repl_format
270
+ when :json then "[x: #{frame.origin.x}, y: #{frame.origin.y}, height: #{frame.size.width}, width: #{frame.size.height}]"
271
+ when :ruby then "[[#{frame.origin.x}, #{frame.origin.y}], [#{frame.size.width}, #{frame.size.height}]]"
272
+ when nil, :objc
273
+ frame.to_s
274
+ else
275
+ raise "Unknown repl_format #{SugarCube::Adjust::repl_format.inspect}"
276
+ end
277
+ end
278
+
233
279
  end
234
280
  end
@@ -4,6 +4,10 @@ class Symbol
4
4
  to_s.get_default
5
5
  end
6
6
 
7
+ def get_default_or(default)
8
+ to_s.get_default_or(default)
9
+ end
10
+
7
11
  def set_default val
8
12
  to_s.set_default val
9
13
  end
@@ -17,10 +21,21 @@ end
17
21
 
18
22
  class String
19
23
 
20
- def get_default
24
+ def get_default(default=nil)
21
25
  NSUserDefaults.standardUserDefaults.objectForKey(self)
22
26
  end
23
27
 
28
+ def get_default_or(default)
29
+ raise "Invalid default value" if default.nil?
30
+
31
+ nsdefault = self.get_default
32
+ if nsdefault.nil?
33
+ self.set_default(default)
34
+ nsdefault = default
35
+ end
36
+ return nsdefault
37
+ end
38
+
24
39
  def set_default val
25
40
  NSUserDefaults.standardUserDefaults.setObject(val, forKey:self)
26
41
  end
@@ -0,0 +1,74 @@
1
+ class NSCoder
2
+
3
+ def [] key
4
+ return self.decodeObjectForKey key
5
+ end
6
+
7
+ def []= key, value
8
+ return self.encodeObject(value, forKey:key)
9
+ end
10
+
11
+ def bool(key)
12
+ return self.decodeBoolForKey(key)
13
+ end
14
+
15
+ def double(key)
16
+ return self.decodeDoubleForKey(key)
17
+ end
18
+
19
+ def float(key)
20
+ return self.decodeFloatForKey(key)
21
+ end
22
+
23
+ def int(key)
24
+ return self.decodeIntegerForKey(key)
25
+ end
26
+
27
+ def point(key)
28
+ return CGPointFromString(self.decodeObjectForKey(key))
29
+ end
30
+
31
+ def rect(key)
32
+ return CGRectFromString(self.decodeObjectForKey(key))
33
+ end
34
+
35
+ def size(key)
36
+ return CGSizeFromString(self.decodeObjectForKey(key))
37
+ end
38
+
39
+ def set(key, toBool:value)
40
+ self.encodeBool(value, forKey:key)
41
+ return self
42
+ end
43
+
44
+ def set(key, toDouble:value)
45
+ self.encodeDouble(value, forKey:key)
46
+ return self
47
+ end
48
+
49
+ def set(key, toFloat:value)
50
+ self.encodeFloat(value, forKey:key)
51
+ return self
52
+ end
53
+
54
+ def set(key, toInt:value)
55
+ self.encodeInteger(value, forKey:key)
56
+ return self
57
+ end
58
+
59
+ def set(key, toPoint:value)
60
+ self.encodeObject(NSStringFromCGPoint(value), forKey:key)
61
+ return self
62
+ end
63
+
64
+ def set(key, toRect:value)
65
+ self.encodeObject(NSStringFromCGRect(value), forKey:key)
66
+ return self
67
+ end
68
+
69
+ def set(key, toSize:value)
70
+ self.encodeObject(NSStringFromCGSize(value), forKey:key)
71
+ return self
72
+ end
73
+
74
+ end
@@ -37,7 +37,13 @@ class Symbol
37
37
  white: :whiteColor,
38
38
  clear: :clearColor,
39
39
 
40
- table_view: :groupTableViewBackgroundColor,
40
+ light_text: :lightTextColor,
41
+ dark_text: :darkTextColor,
42
+
43
+ table_view: :groupTableViewBackgroundColor,
44
+ scroll_view: :scrollViewTexturedBackgroundColor,
45
+ flipside: :viewFlipsideBackgroundColor,
46
+ under_page: :underPageBackgroundColor,
41
47
  }
42
48
 
43
49
  @css_colors = {
@@ -0,0 +1,35 @@
1
+ class UIColor
2
+ def to_s
3
+ system_color = nil
4
+ Symbol.uicolors.each_pair do |color, method|
5
+ if UIColor.send(method) == self
6
+ if self.alpha < 1
7
+ system_color = "UIColor.#{method}(#{alpha})"
8
+ else
9
+ system_color = "UIColor.#{method}"
10
+ end
11
+ break
12
+ end
13
+ end
14
+ return system_color if system_color
15
+
16
+ red = (self.red * 255).round << 16
17
+ green = (self.green * 255).round << 8
18
+ blue = (self.blue * 255).round
19
+ my_color = red + green + blue
20
+
21
+ inside = "0x#{my_color.to_s(16)}"
22
+ Symbol.css_colors.each_pair do |color, hex|
23
+ if hex == my_color
24
+ inside = color.inspect
25
+ break
26
+ end
27
+ end
28
+
29
+ if self.alpha < 1
30
+ return "UIColor.color(#{inside}, #{alpha})"
31
+ else
32
+ return "UIColor.color(#{inside})"
33
+ end
34
+ end
35
+ end
@@ -1,8 +1,8 @@
1
1
  class UIView
2
2
 
3
3
  def to_s
4
- "#{self.class.name}(##{self.object_id.to_s(16)}, #{self.frame}, " +
5
- (self.superview ? " child of #{self.superview.class.name}(##{self.superview.object_id.to_s(16)})" : '')
4
+ "#{self.class.name}(##{self.object_id.to_s(16)}, #{SugarCube::Adjust::format_frame(self.frame)})" +
5
+ (self.superview ? ", child of #{self.superview.class.name}(##{self.superview.object_id.to_s(16)})" : '')
6
6
  end
7
7
 
8
8
  end
@@ -2,30 +2,25 @@
2
2
  class UIColor
3
3
  def uicolor ; self ; end
4
4
 
5
+ def red
6
+ _sugarcube_colors[:red]
7
+ end
5
8
 
6
- def to_s
7
- alpha = self.alpha.to_s
9
+ def green
10
+ _sugarcube_colors[:green]
11
+ end
8
12
 
9
- Symbol.uicolors.each_pair do |color, method|
10
- if UIColor.send(method) == self
11
- return "UIColor.#{method}(#{alpha})"
12
- end
13
- end
13
+ def blue
14
+ _sugarcube_colors[:blue]
15
+ end
14
16
 
15
- red = (self.red * 255).to_i << 16
16
- green = (self.green * 255).to_i << 8
17
- blue = (self.blue * 255).to_i
18
- my_color = red + green + blue
19
- Symbol.css_colors.each_pair do |color, hex|
20
- if hex == my_color
21
- return "UIColor.color(#{color.inspect}, #{alpha})"
22
- end
23
- end
24
- return "UIColor.color(#{red}, #{green}, #{blue}, #{alpha})"
17
+ def alpha
18
+ _sugarcube_colors[:alpha]
25
19
  end
26
20
 
27
- def color
28
- if not @color
21
+ private
22
+ def _sugarcube_colors
23
+ @color ||= begin
29
24
  red = Pointer.new(:float)
30
25
  green = Pointer.new(:float)
31
26
  blue = Pointer.new(:float)
@@ -38,24 +33,6 @@ class UIColor
38
33
  alpha: alpha[0],
39
34
  }
40
35
  end
41
- @color
42
- end
43
-
44
- def red
45
- self.color[:red]
46
- end
47
-
48
- def green
49
- self.color[:green]
50
36
  end
51
37
 
52
- def blue
53
- self.color[:blue]
54
- end
55
-
56
- def alpha
57
- self.color[:alpha]
58
- end
59
-
60
-
61
38
  end
@@ -24,6 +24,7 @@ class UIView
24
24
 
25
25
  def <<(view)
26
26
  self.addSubview view
27
+ return self
27
28
  end
28
29
 
29
30
  def show
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.9.3'
2
+ Version = '0.9.4'
3
3
  end
@@ -29,8 +29,4 @@ DESC
29
29
  gem.test_files = gem.files.grep(%r{^spec/})
30
30
 
31
31
  gem.require_paths = ['lib']
32
-
33
- gem.add_dependency 'rake'
34
- gem.add_development_dependency 'rspec'
35
-
36
32
  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.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,30 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-27 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: &70363874967320 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *70363874967320
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
- requirement: &70363874965460 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: *70363874965460
13
+ date: 2012-10-03 00:00:00.000000000 Z
14
+ dependencies: []
37
15
  description: ! '== Description
38
16
 
39
17
 
@@ -75,6 +53,7 @@ files:
75
53
  - lib/sugarcube/fixnum.rb
76
54
  - lib/sugarcube/modal.rb
77
55
  - lib/sugarcube/notifications.rb
56
+ - lib/sugarcube/nscoder.rb
78
57
  - lib/sugarcube/nsdate.rb
79
58
  - lib/sugarcube/nsdate_delta.rb
80
59
  - lib/sugarcube/nsindexpath.rb
@@ -86,6 +65,7 @@ files:
86
65
  - lib/sugarcube/symbol/symbol_uicolor.rb
87
66
  - lib/sugarcube/timer.rb
88
67
  - lib/sugarcube/to_s/nsset.rb
68
+ - lib/sugarcube/to_s/uicolor.rb
89
69
  - lib/sugarcube/to_s/uievent.rb
90
70
  - lib/sugarcube/to_s/uitouch.rb
91
71
  - lib/sugarcube/to_s/uiview.rb
@@ -124,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
104
  version: '0'
125
105
  requirements: []
126
106
  rubyforge_project:
127
- rubygems_version: 1.8.11
107
+ rubygems_version: 1.8.24
128
108
  signing_key:
129
109
  specification_version: 3
130
110
  summary: Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully