bluepotion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +10 -0
  3. data/lib/bluepotion.rb +16 -0
  4. data/lib/project/ext/activity.rb +62 -0
  5. data/lib/project/ext/array_list.rb +25 -0
  6. data/lib/project/ext/fragment.rb +2 -0
  7. data/lib/project/ext/object.rb +105 -0
  8. data/lib/project/ext/string.rb +23 -0
  9. data/lib/project/ext/view.rb +81 -0
  10. data/lib/project/potion.rb +50 -0
  11. data/lib/project/pro_motion/pm_activity.rb +38 -0
  12. data/lib/project/pro_motion/pm_application.rb +71 -0
  13. data/lib/project/pro_motion/pm_home_activity.rb +14 -0
  14. data/lib/project/pro_motion/pm_screen.rb +67 -0
  15. data/lib/project/pro_motion/pm_screen_module.rb +165 -0
  16. data/lib/project/pro_motion/pm_single_fragment_activity.rb +31 -0
  17. data/lib/project/ruby_motion_query/rmq/actions.rb +48 -0
  18. data/lib/project/ruby_motion_query/rmq/base.rb +260 -0
  19. data/lib/project/ruby_motion_query/rmq/data.rb +64 -0
  20. data/lib/project/ruby_motion_query/rmq/debug.rb +9 -0
  21. data/lib/project/ruby_motion_query/rmq/enumerablish.rb +99 -0
  22. data/lib/project/ruby_motion_query/rmq/events.rb +28 -0
  23. data/lib/project/ruby_motion_query/rmq/factory.rb +47 -0
  24. data/lib/project/ruby_motion_query/rmq/position.rb +2 -0
  25. data/lib/project/ruby_motion_query/rmq/selectors.rb +72 -0
  26. data/lib/project/ruby_motion_query/rmq/styles.rb +108 -0
  27. data/lib/project/ruby_motion_query/rmq/subviews.rb +95 -0
  28. data/lib/project/ruby_motion_query/rmq/tags.rb +58 -0
  29. data/lib/project/ruby_motion_query/rmq/traverse.rb +287 -0
  30. data/lib/project/ruby_motion_query/rmq/utils.rb +36 -0
  31. data/lib/project/ruby_motion_query/rmq/version.rb +6 -0
  32. data/lib/project/ruby_motion_query/rmq_activity_data.rb +3 -0
  33. data/lib/project/ruby_motion_query/rmq_app.rb +9 -0
  34. data/lib/project/ruby_motion_query/rmq_color.rb +121 -0
  35. data/lib/project/ruby_motion_query/rmq_device.rb +47 -0
  36. data/lib/project/ruby_motion_query/rmq_event.rb +1 -0
  37. data/lib/project/ruby_motion_query/rmq_font.rb +61 -0
  38. data/lib/project/ruby_motion_query/rmq_image.rb +55 -0
  39. data/lib/project/ruby_motion_query/rmq_rect.rb +576 -0
  40. data/lib/project/ruby_motion_query/rmq_screen_data.rb +3 -0
  41. data/lib/project/ruby_motion_query/rmq_stylesheet.rb +39 -0
  42. data/lib/project/ruby_motion_query/rmq_view_data.rb +88 -0
  43. data/lib/project/ruby_motion_query/stylers/rmq_button_styler.rb +3 -0
  44. data/lib/project/ruby_motion_query/stylers/rmq_image_button_styler.rb +3 -0
  45. data/lib/project/ruby_motion_query/stylers/rmq_image_view_styler.rb +24 -0
  46. data/lib/project/ruby_motion_query/stylers/rmq_linear_layout_styler.rb +32 -0
  47. data/lib/project/ruby_motion_query/stylers/rmq_relative_layout_styler.rb +7 -0
  48. data/lib/project/ruby_motion_query/stylers/rmq_styler_helper.rb +3 -0
  49. data/lib/project/ruby_motion_query/stylers/rmq_text_view_styler.rb +50 -0
  50. data/lib/project/ruby_motion_query/stylers/rmq_view_styler.rb +201 -0
  51. data/lib/project/version.rb +3 -0
  52. data/templates/screen/app/screens/name_screen.rb +20 -0
  53. data/templates/screen/app/stylesheets/name_screen_stylesheet.rb +24 -0
  54. data/templates/screen/spec/screens/name_screen_spec.rb +8 -0
  55. metadata +119 -0
@@ -0,0 +1,47 @@
1
+ class RMQ
2
+ def device
3
+ RMQDevice
4
+ end
5
+
6
+ def self.device
7
+ RMQDevice
8
+ end
9
+ end
10
+
11
+ class RMQDevice
12
+ class << self
13
+
14
+ def os_version
15
+ @os_version ||= Android::Os::Build::VERSION.new.RELEASE.to_f
16
+ end
17
+
18
+ def os_code_name
19
+ @os_code_name ||= Android::Os::Build::VERSION.new.CODENAME
20
+ end
21
+
22
+ def sdk_version
23
+ @sdk_version ||= Android::Os::Build::VERSION.new.SDK_INT
24
+ end
25
+
26
+ def sdk_at_least?(version)
27
+ version.to_i <= sdk_version
28
+ end
29
+
30
+ def display
31
+ @display ||= RMQ.app.context.getSystemService(RMQ.app.context.WINDOW_SERVICE).defaultDisplay
32
+ end
33
+
34
+ def width
35
+ @width ||= display.width
36
+ end
37
+
38
+ def height
39
+ @height ||= display.height
40
+ end
41
+
42
+ def dpi
43
+ #TODO
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,61 @@
1
+ class RMQ
2
+ def self.font
3
+ RMQFont
4
+ end
5
+
6
+ def font
7
+ RMQFont
8
+ end
9
+ end
10
+
11
+ class RMQFont
12
+ attr_accessor :name, :size, :font_family, :text_style
13
+
14
+ def initialize(name, font_family, size, text_style)
15
+ @name = name
16
+ @font_family = font_family
17
+ @text_style = text_style
18
+ @size = size
19
+ end
20
+
21
+ def inspect
22
+ "<RMQFont #{@name} \"#{@font_family}\" #{@size} #{@text_style}>"
23
+ end
24
+
25
+ def to_s
26
+ self.inspect
27
+ end
28
+
29
+ def sdk_text_style
30
+ case @text_style
31
+ when :bold
32
+ Android::Graphics::Typeface::BOLD
33
+ when :italic
34
+ Android::Graphics::Typeface::ITALIC
35
+ when :bold_italic
36
+ Android::Graphics::Typeface::BOLD_ITALIC
37
+ when :normal
38
+ Android::Graphics::Typeface::NORMAL
39
+ end
40
+ end
41
+
42
+ def to_typeface
43
+ Android::Graphics::Typeface.create(@font_family, sdk_text_style)
44
+ end
45
+
46
+ class << self
47
+ def add_named(name, font_family, size, text_style)
48
+ font_cache[name] = RMQFont.new(name, font_family, size, text_style)
49
+ end
50
+
51
+ def method_missing(font_key)
52
+ # define_singleton_method isn't implemented in Android :'(
53
+ font_cache[font_key]
54
+ end
55
+
56
+ def font_cache
57
+ @font_cache ||= {}
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,55 @@
1
+ class RMQ
2
+ # @return [RMQImageUtils]
3
+ def self.image
4
+ RMQImageUtils
5
+ end
6
+
7
+ # @return [RMQImageUtils]
8
+ def image
9
+ RMQImageUtils
10
+ end
11
+ end
12
+
13
+ class RMQImageUtils
14
+ class << self
15
+ DEFAULT_IMAGE_EXT = 'png'
16
+
17
+ # @return [UIImage]
18
+ def resource(file_base_name, opts = {})
19
+ ext = opts[:ext] || DEFAULT_IMAGE_EXT
20
+ #cached = opts[:cached]
21
+ #cached = true if cached.nil?
22
+
23
+ constant = R::Drawable.const_get(file_base_name.capitalize)
24
+ constant
25
+ #if cached
26
+ ##UIImage.imageNamed("#{file_base_name}.#{ext}")
27
+ #else
28
+ #R::Drawable::Foo
29
+ #R::Drawable::Bluepotion_logo
30
+ #file_base_name << '@2x' if RMQ.device.retina?
31
+ #file = NSBundle.mainBundle.pathForResource(file_base_name, ofType: ext)
32
+ #UIImage.imageWithContentsOfFile(file)
33
+ #end
34
+ end
35
+ end
36
+ end
37
+
38
+ __END__
39
+
40
+
41
+ A 48x48 image, should be in these sizes (3:4:6:8):
42
+
43
+
44
+ drawable-hdpi
45
+ drawable-ldpi
46
+ drawable-mdpi
47
+ drawable-xhdpi
48
+ drawable-xxhdpi
49
+
50
+
51
+ http://labs.rampinteractive.co.uk/android_dp_px_calculator/
52
+
53
+ http://romannurik.github.io/AndroidAssetStudio/nine-patches.html
54
+
55
+ http://grahamtodman.co.uk/blog/2013/02/how-to-design-android-apps-in-photoshop-what-the-frak-is-a-dp/
@@ -0,0 +1,576 @@
1
+ __END__
2
+
3
+ class RMQ
4
+ RECT_WHITELIST = [:grid, :g, :l, :left, :x, :fl, :top, :t, :y, :w, :width, :h, :height, :below_prev, :bp, :below_previous, :left_of_prev, :lop, :left_of_previous, :r, :right, :b, :bottom, :from_right, :fr, :from_bottom, :fb, :centered, :padding, :p, :above_prev, :ap, :above_previous, :rop, :right_of_prev, :right_of_previous, :left_of_prev, :lop, :left_of_previous]
5
+
6
+ # @return RMQRect or array of RMQRect
7
+ #
8
+ # @example
9
+ # left = rmq(my_view).frame.left
10
+ def frame(params = nil)
11
+ if params
12
+ frame = params
13
+ self
14
+ else
15
+ if selected.length == 1
16
+ RMQRect.frame_for_view(selected.first)
17
+ else
18
+ selected.map{|s| RMQRect.frame_for_view(s)}
19
+ end
20
+ end
21
+ end
22
+
23
+ # Same as layout:
24
+ # rmq(my_view).layout(l: 10, t: 20, w: 100, h: 150)
25
+ #
26
+ # Always applied in this order, regardless of the hash order:
27
+ # grid
28
+ # l, t, w, h
29
+ # prev, next
30
+ # from_right, from_bottom
31
+ # right, bottom
32
+ # left and right applied together (will change width)
33
+ # top and bottom applied together (will change height)
34
+ # centered
35
+ # padding
36
+ #
37
+ # @example
38
+ # rmq(my_view).frame = :full
39
+ # rmq(my_view).frame = {l: 10, t: 20, w: 100, h: 150}
40
+ # rmq(my_view).frame = {t: 20, h: 150, l: 10, w: 100}
41
+ # rmq(my_view).frame = {l: 10, t: 20}
42
+ # rmq(my_view).frame = {h: 20}
43
+ # rmq(my_view).frame = {l: :prev, t: 20, w: 100, h: 150}
44
+ # rmq(my_view).frame = {l: 10, below_prev: 10, w: prev, h: 150}
45
+ # rmq(my_view).frame = {left: 10, top: 20, width: 100, height: 150}
46
+ # rmq(my_view).frame = {l: 10, t: 10, fr: 10, fb: 10}
47
+ # rmq(my_view).frame = {width: 50, height: 20, centered: :both}
48
+ # rmq(my_view).frame = "a1:b5"
49
+ # rmq(my_view, my_other_view).frame = {grid: "b2", w: 100, h: 200}
50
+ # rmq(my_view, my_other_view).frame = {g: "b2", w: 100, h: 200}
51
+ #
52
+ # @example with padding
53
+ # rmq(my_view).frame = {grid: "b2:d14", padding: 5}
54
+ # rmq(my_view).frame = {grid: "b2:d14", padding: {l: 5, t: 0, r: 5, b:0}}
55
+ def frame=(value)
56
+ selected.each do |view|
57
+ RMQRect.update_view_frame(view, value)
58
+ end
59
+ end
60
+
61
+ def bounds
62
+ if selected.length == 1
63
+ RMQRect.bounds_for_view(selected.first)
64
+ else
65
+ selected.map{|s| RMQRect.bounds_for_view(s)}
66
+ end
67
+ end
68
+
69
+ def bounds=(value)
70
+ selected.each do |view|
71
+ RMQRect.bounds_for_view(view).update(value, self.grid).apply_to_bounds
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+
78
+ # RMQ Rect
79
+ #
80
+ # *******************---*******---*************************** value options
81
+ # * | | * -------------
82
+ # * | | * Integer
83
+ # * | | * signed Integer
84
+ # * top | * Float
85
+ # * | | * String
86
+ # * | | *
87
+ # * --- | * also
88
+ # * ***************|***** --- * -----------------------
89
+ # * * view | * | * :full
90
+ # * * | * | * :right_of_prev (:rop)
91
+ # * * bottom * | * :left_of_prev (:lop)
92
+ # * * | * | * :below_prev (:bp)
93
+ # *|--- left ---|* | * | * :above_prev (:ap)
94
+ # * * | * height * :grid (:g)
95
+ # * * | * | * :padding (:p)
96
+ # * * | * | * int or hash: l,t,b,r
97
+ # *|-------------------- right -+---|* | *
98
+ # * * | * | * abbreviations
99
+ # * * | * |--+--from_right----|* -----------------------
100
+ # * * --- * | * :l, :t, :w, :h
101
+ # * ***************---*** --- * :r, :b
102
+ # * | * :fr, fb
103
+ # * |------ width - + -| *
104
+ # * | * :centered options
105
+ # * | * -----------------------
106
+ # * from_bottom * :horizontal
107
+ # * | * :vertical
108
+ # * | * :both
109
+ # * --- *
110
+ # ***********************************************************
111
+ #
112
+ class RMQRect
113
+ attr_reader :view
114
+
115
+ class << self
116
+
117
+ def update_view_frame(view, params)
118
+ view.frame = object_to_cg_rect(params, view, view.frame, view.rmq.grid)
119
+ end
120
+
121
+ def update_view_bounds(view, params)
122
+ view.frame = object_to_cg_rect(params, view, view.bounds, view.rmq.grid)
123
+ end
124
+
125
+ # Previous sibling
126
+ def previous_view(view)
127
+ if view
128
+ pv = view.rmq.prev.get
129
+ if RMQ.is_blank?(pv)
130
+ nil
131
+ else
132
+ pv
133
+ end
134
+ end
135
+ end
136
+
137
+ def frame_for_view(view)
138
+ new(view.frame, view)
139
+ end
140
+
141
+ def bounds_for_view(view)
142
+ new(view.bounds, view)
143
+ end
144
+
145
+ # Used internally, don't use this
146
+ #
147
+ # In singleton for performance # TODO, test if this is necessary
148
+ def object_to_cg_rect(o, view = nil, existing_rect = nil, grid = nil)
149
+ if o.is_a?(Hash)
150
+ a = rect_hash_to_rect_array(view, existing_rect, o, grid)
151
+ CGRectMake(a[0], a[1], a[2], a[3])
152
+ elsif o == :full
153
+ if view && (sv = view.superview)
154
+ sv.bounds
155
+ else
156
+ rmq.root_view.bounds
157
+ end
158
+ elsif o.is_a?(RMQRect)
159
+ o.to_cgrect
160
+ elsif grid && o.is_a?(String)
161
+ a = rect_hash_to_rect_array(view, existing_rect, {grid: o}, grid)
162
+ CGRectMake(a[0], a[1], a[2], a[3])
163
+ elsif o.is_a?(Array)
164
+ case o.length
165
+ when 4
166
+ CGRectMake(o[0], o[1], o[2], o[3])
167
+ when 2
168
+ o
169
+ end
170
+ else
171
+ o # CGRect, etc
172
+ end
173
+ end
174
+
175
+ # Used internally, don't use this
176
+ #
177
+ # In singleton for performance # TODO, test if this is necessary
178
+ def rect_hash_to_rect_array(view, existing_rect, params, grid = nil)
179
+ # TODO check if this is performant, it should be
180
+ if (sv = view.superview) && (vc = view.rmq_data.view_controller)
181
+ not_in_root_view = !(vc.view == sv)
182
+ end
183
+
184
+ # performant warn if hash has keys that are not whitelisted
185
+ unknown_keys = params.keys - RMQ::RECT_WHITELIST
186
+ unless unknown_keys.empty?
187
+ puts "\n[RMQ ERROR] rect keys #{unknown_keys} don't exist. Verify your hash for #{view.class.name} uses approved keys - #{RMQ::RECT_WHITELIST}\n\n"
188
+ end
189
+
190
+ # Grid
191
+ if grid
192
+ if params_g = params[:grid] || params[:g]
193
+ params.delete(:grid)
194
+ params.delete(:g)
195
+
196
+ grid_h = grid[params_g]
197
+ params = grid_h.merge(params)
198
+ end
199
+ end
200
+
201
+ params_l = params[:l] || params[:left] || params[:x] || params[:fl]
202
+ params_t = params[:t] || params[:top] || params[:y]
203
+ params_w = params[:w] || params[:width]
204
+ params_h = params[:h] || params[:height]
205
+
206
+ below_prev = params[:below_prev] || params[:bp] || params[:below_previous]
207
+ above_prev = params[:above_prev] || params[:ap] || params[:above_previous]
208
+ right_of_prev = params[:right_of_prev] || params[:rop] || params[:right_of_previous]
209
+ left_of_prev = params[:left_of_prev] || params[:lop] || params[:left_of_previous]
210
+
211
+ l = params_l || existing_rect.origin.x
212
+ t = params_t || existing_rect.origin.y
213
+ w = params_w || existing_rect.size.width
214
+ h = params_h || existing_rect.size.height
215
+
216
+ r = params[:r] || params[:right]
217
+ b = params[:b] || params[:bottom]
218
+
219
+ fr = params[:from_right] || params[:fr]
220
+ fb = params[:from_bottom] || params[:fb]
221
+
222
+ centered = params[:centered]
223
+
224
+ # Previous
225
+ if prev_view = previous_view(view)
226
+ if params_g && (prev_sv = prev_view.superview)
227
+
228
+ previous_root_view_point = vc.view.convertPoint(prev_view.origin, fromView: prev_sv)
229
+
230
+ if below_prev
231
+ t = params_t = previous_root_view_point.y + prev_view.frame.size.height + below_prev
232
+ elsif above_prev
233
+ t = params_t = previous_root_view_point.y - above_prev - h
234
+ end
235
+
236
+ if right_of_prev
237
+ l = params_l = previous_root_view_point.x + prev_view.frame.size.width + right_of_prev
238
+ elsif left_of_prev
239
+ l = params_l = previous_root_view_point.x - left_of_prev - w
240
+ end
241
+
242
+ else
243
+ if below_prev
244
+ t = prev_view.frame.origin.y + prev_view.frame.size.height + below_prev
245
+ elsif above_prev
246
+ t = prev_view.frame.origin.y - above_prev - h
247
+ end
248
+
249
+ if right_of_prev
250
+ l = prev_view.frame.origin.x + prev_view.frame.size.width + right_of_prev
251
+ elsif left_of_prev
252
+ l = prev_view.frame.origin.x - left_of_prev - w
253
+ end
254
+ end
255
+ else
256
+ if below_prev
257
+ t = below_prev
258
+ elsif above_prev
259
+ t = above_prev - h
260
+ end
261
+
262
+ if right_of_prev
263
+ l = right_of_prev
264
+ elsif left_of_prev
265
+ l = left_of_prev - w
266
+ end
267
+ end
268
+
269
+ if sv
270
+ if (fr || fb || centered) # Needs size
271
+
272
+ # Horrible horrible hack, TODO fix. This is here because
273
+ # the root_view's height isn't changed until after viewDidLoad when
274
+ # vc.edgesForExtendedLayout = UIRectEdgeNone.
275
+ # Not sure how often people use UIRectEdgeNone as I never do,
276
+ # perhaps an edge case that should be isolated in some wayo
277
+ # I hate to have to check and calc this every time
278
+ if vc && !not_in_root_view && (vc.edgesForExtendedLayout == UIRectEdgeNone)
279
+ sv_size = CGSizeMake(sv.bounds.size.width, rmq.device.screen_height - 64)
280
+ else
281
+ sv_size = sv.bounds.size
282
+ end
283
+ end
284
+ end
285
+
286
+ # From right, from_bottom
287
+ if (fr || fb) && sv
288
+ if fr
289
+ if params_l || left_of_prev || right_of_prev
290
+ w = sv_size.width - l - fr
291
+ else
292
+ l = sv_size.width - w - fr
293
+ end
294
+ end
295
+
296
+ if fb
297
+ if params_t || below_prev || above_prev
298
+ h = sv_size.height - t - fb
299
+ else
300
+ t = sv_size.height - h - fb
301
+ end
302
+ end
303
+ end
304
+
305
+ # Right and bottom
306
+ if r && !fr && !params_l
307
+ l = r - w
308
+ end
309
+ if b && !fb && !params_t
310
+ t = b - h
311
+ end
312
+
313
+ # Left and right applied together
314
+ if params_l && r && !params_w
315
+ w = r - l
316
+ end
317
+ # Top and bottom applied together
318
+ if params_t && b && !params_h
319
+ h = b - t
320
+ end
321
+
322
+ # Centered, :horizontal, :vertical, :both
323
+ if sv && centered
324
+ case centered
325
+ when :horizontal
326
+ l = (sv_size.width / 2) - (w / 2)
327
+ when :vertical
328
+ t = (sv_size.height / 2) - (h / 2)
329
+ when :both
330
+ l = (sv_size.width / 2) - (w / 2)
331
+ t = (sv_size.height / 2) - (h / 2)
332
+ end
333
+ end
334
+
335
+ if padding = params[:padding] || params[:p]
336
+ if padding.is_a?(Hash)
337
+ padding_l = padding[:l] || padding[:left] || 0
338
+ padding_t = padding[:t] || padding[:top] || 0
339
+ padding_r = padding[:r] || padding[:right] || 0
340
+ padding_b = padding[:b] || padding[:bottom] || 0
341
+ l += padding_l
342
+ t += padding_t
343
+ w -= (padding_l + padding_r)
344
+ h -= (padding_t + padding_b)
345
+ else
346
+ l += padding
347
+ t += padding
348
+ w -= (padding * 2)
349
+ h -= (padding * 2)
350
+ end
351
+ end
352
+
353
+ if params_g && not_in_root_view # Change to root_view_space
354
+ point = CGPointMake(l,t)
355
+ root_view_point = vc.view.convertPoint(point, toView: sv)
356
+ l = root_view_point.x
357
+ t = root_view_point.y
358
+ end
359
+
360
+ [l,t,w,h]
361
+ end
362
+
363
+ end # << self
364
+
365
+ def initialize(params, view = nil, grid = nil)
366
+ @left = @top = @width = @height = 0
367
+ @view = view
368
+ update params, grid
369
+ end
370
+
371
+ def update(params, grid = nil)
372
+ # Doing all of the updates to the Rect in singleton for performance.
373
+ # It would be better to be done inside an actual Rect instance, but that
374
+ # would require creating a lot of temporary objects.
375
+ # TODO performance and see if there is any real loss bringing
376
+ # object_to_cg_rect into Rect instance
377
+ #
378
+ # If we did it that way, then we'd create a new instance, then appy the
379
+ # rect instance to the frame or bounds, like so:
380
+ # Rect.new(params, view, grid).apply_to_frame
381
+ cg_rect = RMQRect.object_to_cg_rect(params, @view, self.to_cgrect, grid)
382
+
383
+ @left = cg_rect.origin.x
384
+ @top = cg_rect.origin.y
385
+ @width = cg_rect.size.width
386
+ @height = cg_rect.size.height
387
+ end
388
+
389
+ def apply_to_frame
390
+ @view.frame = to_cgrect if @view
391
+ end
392
+ def apply_to_bounds
393
+ @view.bounds = to_cgrect if @view
394
+ end
395
+
396
+ def left
397
+ @left
398
+ end
399
+ alias :l :left
400
+ alias :x :left
401
+
402
+ def right
403
+ @left + @width
404
+ end
405
+ alias :r :right
406
+
407
+ def from_right
408
+ if @view && (sv = @view.superview)
409
+ sv.size.width - right
410
+ end
411
+ end
412
+ alias :fr :from_right
413
+
414
+ def top
415
+ @top
416
+ end
417
+ alias :t :top
418
+ alias :y :top
419
+
420
+ def bottom
421
+ @top + @height
422
+ end
423
+ alias :b :bottom
424
+
425
+ def from_bottom
426
+ if @view && (sv = @view.superview)
427
+ sv.bounds.size.height - bottom
428
+ end
429
+ end
430
+ alias :fb :from_bottom
431
+
432
+ def width
433
+ @width
434
+ end
435
+ alias :w :width
436
+
437
+ def height
438
+ @height
439
+ end
440
+ alias :h :height
441
+
442
+ def z_order
443
+ if @view && (sv = @view.superview)
444
+ sv.subviews.to_a.index(@view) # is there a better way??
445
+ end
446
+ end
447
+
448
+ #def origin
449
+ #to_cgpoint
450
+ #end
451
+
452
+ #def size
453
+ #to_cgsize
454
+ #end
455
+
456
+ #def point_in_root_view
457
+ #if @view && (sv = @view.superview) && (vc = view.rmq.view_controller)
458
+ #vc.view.convertPoint(CGPointMake(@left,@top), fromView: sv)
459
+ #end
460
+ #end
461
+
462
+ #def rect_in_root_view
463
+ #if @view && (sv = @view.superview) && (vc = view.rmq.view_controller)
464
+ #point = vc.view.convertPoint(CGPointMake(@left,@top), fromView: sv)
465
+ #RMQRect.new({l: point.x, t: point.y, w: @view.size.width, h: @view.size.height}, @view)
466
+ #end
467
+ #end
468
+
469
+ #def left_in_root_view
470
+ #if point = point_in_root_view
471
+ #point.x
472
+ #end
473
+ #end
474
+
475
+ #def top_in_root_view
476
+ #if point = point_in_root_view
477
+ #point.y
478
+ #end
479
+ #end
480
+
481
+ # TODO add center
482
+
483
+ #def z_position
484
+ #if @view
485
+ #@view.layer.zPosition
486
+ #end
487
+ #end
488
+
489
+ #def to_cgpoint
490
+ #CGPointMake(@left, @top)
491
+ #end
492
+
493
+ #def to_cgsize
494
+ #CGSizeMake(@width, @height)
495
+ #end
496
+
497
+ #def to_cgrect
498
+ #CGRectMake(@left, @top, @width, @height)
499
+ #end
500
+ def to_a
501
+ [@left, @top, @width, @height]
502
+ end
503
+ def to_h
504
+ {left: @left, top: @top, width: @width, height: @height}
505
+ end
506
+
507
+ #def inspect
508
+ #format = '#0.#'
509
+ #s = "RMQRect {l: #{RMQ.format.numeric(left, format)}"
510
+ #s << ", t: #{RMQ.format.numeric(top, format)}"
511
+ #s << ", w: #{RMQ.format.numeric(width, format)}"
512
+ #s << ", h: #{RMQ.format.numeric(height, format)}}"
513
+ #s
514
+ #end
515
+
516
+ def log
517
+ def i_f_to_s(int_or_float)
518
+ if int_or_float % 1 == 0
519
+ int_or_float.to_i.to_s
520
+ else
521
+ int_or_float.to_s
522
+ end
523
+ end
524
+
525
+ l = i_f_to_s(left.round(2)).ljust(5)
526
+ t = i_f_to_s(top.round(2)).rjust(5)
527
+ w = i_f_to_s(width.round(2)).ljust(5)
528
+ h = i_f_to_s(height.round(2)).ljust(5)
529
+ b = i_f_to_s(bottom.round(2)).rjust(5)
530
+ r = i_f_to_s(right.round(2)).ljust(5)
531
+ fr = i_f_to_s(from_right.round(2)).ljust(5)
532
+ fb = i_f_to_s(from_bottom.round(2)).rjust(5)
533
+
534
+ ww = i_f_to_s(rmq.app.window.size.width.round(2))
535
+ wh = i_f_to_s(rmq.app.window.size.height.round(2))
536
+
537
+ if @view && (sv = @view.superview)
538
+ sw = i_f_to_s(sv.bounds.size.width.round(2))
539
+ sh = i_f_to_s(sv.bounds.size.height.round(2))
540
+ end
541
+
542
+ out = %(
543
+ *****************---*******---**************************
544
+ * | | * window
545
+ * #{ t} top | * {w: #{ww}, h: #{wh}}
546
+ * | | *
547
+ * --- | * superview
548
+ * ***************|***** --- * {w: #{sw}, h: #{sh}}
549
+ * * | * | *
550
+ * * | * | *
551
+ * * #{ b} bottom * | * view
552
+ * #{ l} * | * | * {l: #{l.strip}, t: #{t.strip},
553
+ *|-- left --|* | * | * w: #{w.strip}, h: #{h.strip}}
554
+ * * | * height #{ h} *
555
+ * * | * | * z_order: #{z_order}
556
+ * * #{ r} | * | * z_position: #{z_position}
557
+ *|------------------ right -+---|* | *
558
+ * * | * | #{fr} * Location in root view
559
+ * * | * |--+--from_right---|* {l: #{i_f_to_s(left_in_root_view)}, t: #{i_f_to_s(top_in_root_view)},
560
+ * * --- * | * w: #{w.strip}, h: #{h.strip}}
561
+ * ***************---*** --- *
562
+ * | *
563
+ * |------ width - + --| *
564
+ * #{ w} | *
565
+ * | *
566
+ * | *
567
+ * #{fb} from_bottom *
568
+ * | *
569
+ * --- *
570
+ ********************************************************
571
+ )
572
+ puts out
573
+ end
574
+
575
+ end
576
+