motion-kit 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +839 -0
  3. data/lib/motion-kit-cocoa/cocoa_util.rb +59 -0
  4. data/lib/motion-kit-cocoa/constraints/constraint.rb +765 -0
  5. data/lib/motion-kit-cocoa/constraints/constraint_placeholder.rb +22 -0
  6. data/lib/motion-kit-cocoa/constraints/constraints_layout.rb +536 -0
  7. data/lib/motion-kit-cocoa/constraints/constraints_target.rb +52 -0
  8. data/lib/motion-kit-cocoa/layouts/cagradientlayer_layout.rb +13 -0
  9. data/lib/motion-kit-cocoa/layouts/calayer_layout.rb +27 -0
  10. data/lib/motion-kit-cocoa/layouts/sugarcube_compat.rb +38 -0
  11. data/lib/motion-kit-ios/dummy.rb +93 -0
  12. data/lib/motion-kit-ios/ios_util.rb +20 -0
  13. data/lib/motion-kit-ios/layouts/constraints_layout.rb +22 -0
  14. data/lib/motion-kit-ios/layouts/layout_device.rb +32 -0
  15. data/lib/motion-kit-ios/layouts/layout_orientation.rb +47 -0
  16. data/lib/motion-kit-ios/layouts/uibutton_layout.rb +52 -0
  17. data/lib/motion-kit-ios/layouts/uiview_layout.rb +45 -0
  18. data/lib/motion-kit-ios/layouts/uiview_layout_autoresizing.rb +75 -0
  19. data/lib/motion-kit-ios/layouts/uiview_layout_constraints.rb +36 -0
  20. data/lib/motion-kit-ios/layouts/uiview_layout_frame.rb +307 -0
  21. data/lib/motion-kit-ios/layouts/uiview_layout_gradient.rb +20 -0
  22. data/lib/motion-kit-osx/dummy.rb +89 -0
  23. data/lib/motion-kit-osx/layouts/constraints_layout.rb +42 -0
  24. data/lib/motion-kit-osx/layouts/nsmenu_extensions.rb +186 -0
  25. data/lib/motion-kit-osx/layouts/nsmenu_layout.rb +109 -0
  26. data/lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb +45 -0
  27. data/lib/motion-kit-osx/layouts/nstablecolumn_layout.rb +12 -0
  28. data/lib/motion-kit-osx/layouts/nstableview_layout.rb +20 -0
  29. data/lib/motion-kit-osx/layouts/nsview_layout.rb +47 -0
  30. data/lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb +75 -0
  31. data/lib/motion-kit-osx/layouts/nsview_layout_constraints.rb +34 -0
  32. data/lib/motion-kit-osx/layouts/nsview_layout_frame.rb +375 -0
  33. data/lib/motion-kit-osx/layouts/nswindow_frame.rb +14 -0
  34. data/lib/motion-kit-osx/layouts/nswindow_layout.rb +77 -0
  35. data/lib/motion-kit-osx/osx_util.rb +16 -0
  36. data/lib/motion-kit.rb +33 -0
  37. data/lib/motion-kit/calculate.rb +263 -0
  38. data/lib/motion-kit/layouts/base_layout.rb +299 -0
  39. data/lib/motion-kit/layouts/base_layout_class_methods.rb +43 -0
  40. data/lib/motion-kit/layouts/parent.rb +68 -0
  41. data/lib/motion-kit/layouts/view_layout.rb +327 -0
  42. data/lib/motion-kit/motion-kit.rb +18 -0
  43. data/lib/motion-kit/object.rb +16 -0
  44. data/lib/motion-kit/util.rb +20 -0
  45. data/lib/motion-kit/version.rb +1 -1
  46. data/spec/ios/apply_styles_spec.rb +21 -0
  47. data/spec/ios/autoresizing_helper_spec.rb +224 -0
  48. data/spec/ios/calculate_spec.rb +322 -0
  49. data/spec/ios/calculator_spec.rb +31 -0
  50. data/spec/ios/constraints_helpers/attribute_lookup_spec.rb +27 -0
  51. data/spec/ios/constraints_helpers/axis_lookup_spec.rb +13 -0
  52. data/spec/ios/constraints_helpers/center_constraints_spec.rb +419 -0
  53. data/spec/ios/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  54. data/spec/ios/constraints_helpers/priority_lookup_spec.rb +19 -0
  55. data/spec/ios/constraints_helpers/relationship_lookup_spec.rb +27 -0
  56. data/spec/ios/constraints_helpers/relative_corners_spec.rb +274 -0
  57. data/spec/ios/constraints_helpers/relative_location_spec.rb +111 -0
  58. data/spec/ios/constraints_helpers/simple_constraints_spec.rb +2763 -0
  59. data/spec/ios/constraints_helpers/size_constraints_spec.rb +422 -0
  60. data/spec/ios/constraints_helpers/view_lookup_constraints_spec.rb +93 -0
  61. data/spec/ios/create_layout_spec.rb +40 -0
  62. data/spec/ios/custom_layout_spec.rb +13 -0
  63. data/spec/ios/deferred_spec.rb +89 -0
  64. data/spec/ios/device_helpers_spec.rb +51 -0
  65. data/spec/ios/frame_helper_spec.rb +1150 -0
  66. data/spec/ios/layer_layout_spec.rb +36 -0
  67. data/spec/ios/layout_extensions_spec.rb +70 -0
  68. data/spec/ios/layout_spec.rb +74 -0
  69. data/spec/ios/layout_state_spec.rb +27 -0
  70. data/spec/ios/motionkit_util_spec.rb +102 -0
  71. data/spec/ios/objc_selectors_spec.rb +10 -0
  72. data/spec/ios/orientation_helper_specs.rb +67 -0
  73. data/spec/ios/parent_layout_spec.rb +19 -0
  74. data/spec/ios/parent_spec.rb +45 -0
  75. data/spec/ios/remove_layout_spec.rb +25 -0
  76. data/spec/ios/root_layout_spec.rb +53 -0
  77. data/spec/ios/setters_spec.rb +63 -0
  78. data/spec/ios/uibutton_layout_spec.rb +24 -0
  79. data/spec/ios/uitextfield_spec.rb +14 -0
  80. data/spec/ios/view_attr_spec.rb +25 -0
  81. data/spec/osx/autoresizing_helper_spec.rb +224 -0
  82. data/spec/osx/constraints_helper_spec.rb +0 -0
  83. data/spec/osx/constraints_helpers/orientation_lookup_spec.rb +13 -0
  84. data/spec/osx/constraints_helpers/simple_constraints_spec.rb +2095 -0
  85. data/spec/osx/constraints_helpers/size_constraints_spec.rb +362 -0
  86. data/spec/osx/create_menu_spec.rb +14 -0
  87. data/spec/osx/create_via_extensions_spec.rb +63 -0
  88. data/spec/osx/deferred_spec.rb +85 -0
  89. data/spec/osx/frame_helper_spec.rb +1881 -0
  90. data/spec/osx/menu_extensions_spec.rb +376 -0
  91. data/spec/osx/menu_layout_spec.rb +157 -0
  92. data/spec/osx/menu_spec.rb +70 -0
  93. data/spec/osx/root_menu_spec.rb +15 -0
  94. metadata +166 -14
@@ -0,0 +1,22 @@
1
+ module MotionKit
2
+ class ConstraintPlaceholder
3
+
4
+ def initialize(type, name, value=nil)
5
+ @type = type
6
+ @name = name
7
+ @value = value
8
+ end
9
+
10
+ def resolve(layout)
11
+ case @type
12
+ when :first
13
+ layout.get(@name)
14
+ when :last
15
+ layout.last(@name)
16
+ when :nth
17
+ layout.nth(@name, @value)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,536 @@
1
+ # @provides MotionKit::ConstraintsLayout
2
+ # @requires MotionKit::BaseLayout
3
+ module MotionKit
4
+ class ConstraintsLayout < BaseLayout
5
+ targets ConstraintsTarget
6
+
7
+ def first(name)
8
+ ConstraintPlaceholder.new(:first, name)
9
+ end
10
+
11
+ def last(name)
12
+ ConstraintPlaceholder.new(:last, name)
13
+ end
14
+
15
+ def nth(name, value)
16
+ ConstraintPlaceholder.new(:nth, name, value)
17
+ end
18
+
19
+ def x(value=nil)
20
+ constraint = Constraint.new(target.view, :left, :equal)
21
+
22
+ if value
23
+ constraint.equals(value)
24
+ end
25
+
26
+ target.add_constraints([constraint])
27
+ return constraint
28
+ end
29
+ alias left x
30
+
31
+ def min_x(value=nil)
32
+ constraint = Constraint.new(target.view, :left, :gte)
33
+
34
+ if value
35
+ constraint.equals(value)
36
+ end
37
+
38
+ target.add_constraints([constraint])
39
+ return constraint
40
+ end
41
+ alias min_left min_x
42
+
43
+ def max_x(value=nil)
44
+ constraint = Constraint.new(target.view, :left, :lte)
45
+
46
+ if value
47
+ constraint.equals(value)
48
+ end
49
+
50
+ target.add_constraints([constraint])
51
+ return constraint
52
+ end
53
+ alias max_left max_x
54
+
55
+ def leading(value=nil)
56
+ constraint = Constraint.new(target.view, :leading, :equal)
57
+
58
+ if value
59
+ constraint.equals(value)
60
+ end
61
+
62
+ target.add_constraints([constraint])
63
+ return constraint
64
+ end
65
+
66
+ def min_leading(value=nil)
67
+ constraint = Constraint.new(target.view, :leading, :gte)
68
+
69
+ if value
70
+ constraint.equals(value)
71
+ end
72
+
73
+ target.add_constraints([constraint])
74
+ return constraint
75
+ end
76
+
77
+ def max_leading(value=nil)
78
+ constraint = Constraint.new(target.view, :leading, :lte)
79
+
80
+ if value
81
+ constraint.equals(value)
82
+ end
83
+
84
+ target.add_constraints([constraint])
85
+ return constraint
86
+ end
87
+
88
+ def center_x(value=nil)
89
+ constraint = Constraint.new(target.view, :center_x, :equal)
90
+
91
+ if value
92
+ constraint.equals(value)
93
+ end
94
+
95
+ target.add_constraints([constraint])
96
+ return constraint
97
+ end
98
+
99
+ def min_center_x(value=nil)
100
+ constraint = Constraint.new(target.view, :center_x, :gte)
101
+
102
+ if value
103
+ constraint.equals(value)
104
+ end
105
+
106
+ target.add_constraints([constraint])
107
+ return constraint
108
+ end
109
+
110
+ def max_center_x(value=nil)
111
+ constraint = Constraint.new(target.view, :center_x, :lte)
112
+
113
+ if value
114
+ constraint.equals(value)
115
+ end
116
+
117
+ target.add_constraints([constraint])
118
+ return constraint
119
+ end
120
+
121
+ def right(value=nil)
122
+ constraint = Constraint.new(target.view, :right, :equal)
123
+
124
+ if value
125
+ constraint.equals(value)
126
+ end
127
+
128
+ target.add_constraints([constraint])
129
+ return constraint
130
+ end
131
+
132
+ def min_right(value=nil)
133
+ constraint = Constraint.new(target.view, :right, :gte)
134
+
135
+ if value
136
+ constraint.equals(value)
137
+ end
138
+
139
+ target.add_constraints([constraint])
140
+ return constraint
141
+ end
142
+
143
+ def max_right(value=nil)
144
+ constraint = Constraint.new(target.view, :right, :lte)
145
+
146
+ if value
147
+ constraint.equals(value)
148
+ end
149
+
150
+ target.add_constraints([constraint])
151
+ return constraint
152
+ end
153
+
154
+ def trailing(value=nil)
155
+ constraint = Constraint.new(target.view, :trailing, :equal)
156
+
157
+ if value
158
+ constraint.equals(value)
159
+ end
160
+
161
+ target.add_constraints([constraint])
162
+ return constraint
163
+ end
164
+
165
+ def min_trailing(value=nil)
166
+ constraint = Constraint.new(target.view, :trailing, :gte)
167
+
168
+ if value
169
+ constraint.equals(value)
170
+ end
171
+
172
+ target.add_constraints([constraint])
173
+ return constraint
174
+ end
175
+
176
+ def max_trailing(value=nil)
177
+ constraint = Constraint.new(target.view, :trailing, :lte)
178
+
179
+ if value
180
+ constraint.equals(value)
181
+ end
182
+
183
+ target.add_constraints([constraint])
184
+ return constraint
185
+ end
186
+
187
+ def y(value=nil)
188
+ constraint = Constraint.new(target.view, :top, :equal)
189
+
190
+ if value
191
+ constraint.equals(value)
192
+ end
193
+
194
+ target.add_constraints([constraint])
195
+ return constraint
196
+ end
197
+ alias top y
198
+
199
+ def min_y(value=nil)
200
+ constraint = Constraint.new(target.view, :top, :gte)
201
+
202
+ if value
203
+ constraint.equals(value)
204
+ end
205
+
206
+ target.add_constraints([constraint])
207
+ return constraint
208
+ end
209
+ alias min_top min_y
210
+
211
+ def max_y(value=nil)
212
+ constraint = Constraint.new(target.view, :top, :lte)
213
+
214
+ if value
215
+ constraint.equals(value)
216
+ end
217
+
218
+ target.add_constraints([constraint])
219
+ return constraint
220
+ end
221
+ alias max_top max_y
222
+
223
+ def center_y(value=nil)
224
+ constraint = Constraint.new(target.view, :center_y, :equal)
225
+
226
+ if value
227
+ constraint.equals(value)
228
+ end
229
+
230
+ target.add_constraints([constraint])
231
+ return constraint
232
+ end
233
+
234
+ def min_center_y(value=nil)
235
+ constraint = Constraint.new(target.view, :center_y, :gte)
236
+
237
+ if value
238
+ constraint.equals(value)
239
+ end
240
+
241
+ target.add_constraints([constraint])
242
+ return constraint
243
+ end
244
+
245
+ def max_center_y(value=nil)
246
+ constraint = Constraint.new(target.view, :center_y, :lte)
247
+
248
+ if value
249
+ constraint.equals(value)
250
+ end
251
+
252
+ target.add_constraints([constraint])
253
+ return constraint
254
+ end
255
+
256
+ def bottom(value=nil)
257
+ constraint = Constraint.new(target.view, :bottom, :equal)
258
+
259
+ if value
260
+ constraint.equals(value)
261
+ end
262
+
263
+ target.add_constraints([constraint])
264
+ return constraint
265
+ end
266
+
267
+ def min_bottom(value=nil)
268
+ constraint = Constraint.new(target.view, :bottom, :gte)
269
+
270
+ if value
271
+ constraint.equals(value)
272
+ end
273
+
274
+ target.add_constraints([constraint])
275
+ return constraint
276
+ end
277
+
278
+ def max_bottom(value=nil)
279
+ constraint = Constraint.new(target.view, :bottom, :lte)
280
+
281
+ if value
282
+ constraint.equals(value)
283
+ end
284
+
285
+ target.add_constraints([constraint])
286
+ return constraint
287
+ end
288
+
289
+ def baseline(value=nil)
290
+ constraint = Constraint.new(target.view, :baseline, :equal)
291
+
292
+ if value
293
+ constraint.equals(value)
294
+ end
295
+
296
+ target.add_constraints([constraint])
297
+ return constraint
298
+ end
299
+
300
+ def min_baseline(value=nil)
301
+ constraint = Constraint.new(target.view, :baseline, :gte)
302
+
303
+ if value
304
+ constraint.equals(value)
305
+ end
306
+
307
+ target.add_constraints([constraint])
308
+ return constraint
309
+ end
310
+
311
+ def max_baseline(value=nil)
312
+ constraint = Constraint.new(target.view, :baseline, :lte)
313
+
314
+ if value
315
+ constraint.equals(value)
316
+ end
317
+
318
+ target.add_constraints([constraint])
319
+ return constraint
320
+ end
321
+
322
+ def width(value=nil)
323
+ constraint = Constraint.new(target.view, :width, :equal)
324
+
325
+ if value
326
+ constraint.equals(value)
327
+ end
328
+
329
+ target.add_constraints([constraint])
330
+ return constraint
331
+ end
332
+ alias w width
333
+
334
+ def min_width(value=nil)
335
+ constraint = Constraint.new(target.view, :width, :gte)
336
+
337
+ if value
338
+ constraint.equals(value)
339
+ end
340
+
341
+ target.add_constraints([constraint])
342
+ return constraint
343
+ end
344
+
345
+ def max_width(value=nil)
346
+ constraint = Constraint.new(target.view, :width, :lte)
347
+
348
+ if value
349
+ constraint.equals(value)
350
+ end
351
+
352
+ target.add_constraints([constraint])
353
+ return constraint
354
+ end
355
+
356
+ def height(value=nil)
357
+ constraint = Constraint.new(target.view, :height, :equal)
358
+
359
+ if value
360
+ constraint.equals(value)
361
+ end
362
+
363
+ target.add_constraints([constraint])
364
+ return constraint
365
+ end
366
+ alias h height
367
+
368
+ def min_height(value=nil)
369
+ constraint = Constraint.new(target.view, :height, :gte)
370
+
371
+ if value
372
+ constraint.equals(value)
373
+ end
374
+
375
+ target.add_constraints([constraint])
376
+ return constraint
377
+ end
378
+
379
+ def max_height(value=nil)
380
+ constraint = Constraint.new(target.view, :height, :lte)
381
+
382
+ if value
383
+ constraint.equals(value)
384
+ end
385
+
386
+ target.add_constraints([constraint])
387
+ return constraint
388
+ end
389
+
390
+ def size(value=nil)
391
+ constraint = SizeConstraint.new(target.view, :size, :equal)
392
+
393
+ if value
394
+ constraint.equals(value)
395
+ end
396
+
397
+ target.add_constraints([constraint])
398
+ return constraint
399
+ end
400
+
401
+ def min_size(value=nil)
402
+ constraint = SizeConstraint.new(target.view, :size, :gte)
403
+
404
+ if value
405
+ constraint.equals(value)
406
+ end
407
+
408
+ target.add_constraints([constraint])
409
+ return constraint
410
+ end
411
+
412
+ def max_size(value=nil)
413
+ constraint = SizeConstraint.new(target.view, :size, :lte)
414
+
415
+ if value
416
+ constraint.equals(value)
417
+ end
418
+
419
+ target.add_constraints([constraint])
420
+ return constraint
421
+ end
422
+
423
+ def center(value=nil)
424
+ constraint = PointConstraint.new(target.view, [:center_x, :center_y], :equal)
425
+
426
+ if value
427
+ constraint.equals(value)
428
+ end
429
+
430
+ target.add_constraints([constraint])
431
+ return constraint
432
+ end
433
+
434
+ def min_center(value=nil)
435
+ constraint = PointConstraint.new(target.view, [:center_x, :center_y], :gte)
436
+
437
+ if value
438
+ constraint.equals(value)
439
+ end
440
+
441
+ target.add_constraints([constraint])
442
+ return constraint
443
+ end
444
+
445
+ def max_center(value=nil)
446
+ constraint = PointConstraint.new(target.view, [:center_x, :center_y], :lte)
447
+
448
+ if value
449
+ constraint.equals(value)
450
+ end
451
+
452
+ target.add_constraints([constraint])
453
+ return constraint
454
+ end
455
+
456
+ def top_left(value=nil)
457
+ constraint = PointConstraint.new(target.view, [:left, :top], :equal)
458
+
459
+ if value
460
+ constraint.equals(value)
461
+ end
462
+
463
+ target.add_constraints([constraint])
464
+ return constraint
465
+ end
466
+ alias origin top_left
467
+
468
+ def top_right(value=nil)
469
+ constraint = PointConstraint.new(target.view, [:right, :top], :equal)
470
+
471
+ if value
472
+ constraint.equals(value)
473
+ end
474
+
475
+ target.add_constraints([constraint])
476
+ return constraint
477
+ end
478
+
479
+ def bottom_left(value=nil)
480
+ constraint = PointConstraint.new(target.view, [:left, :bottom], :equal)
481
+
482
+ if value
483
+ constraint.equals(value)
484
+ end
485
+
486
+ target.add_constraints([constraint])
487
+ return constraint
488
+ end
489
+
490
+ def bottom_right(value=nil)
491
+ constraint = PointConstraint.new(target.view, [:right, :bottom], :equal)
492
+
493
+ if value
494
+ constraint.equals(value)
495
+ end
496
+
497
+ target.add_constraints([constraint])
498
+ return constraint
499
+ end
500
+
501
+ def above(view)
502
+ constraint = Constraint.new(target.view, :bottom, :equal)
503
+ constraint.equals(view, :top)
504
+
505
+ target.add_constraints([constraint])
506
+ return constraint
507
+ end
508
+
509
+ def below(view)
510
+ constraint = Constraint.new(target.view, :top, :equal)
511
+ constraint.equals(view, :bottom)
512
+
513
+ target.add_constraints([constraint])
514
+ return constraint
515
+ end
516
+
517
+ def before(view)
518
+ constraint = Constraint.new(target.view, :right, :equal)
519
+ constraint.equals(view, :left)
520
+
521
+ target.add_constraints([constraint])
522
+ return constraint
523
+ end
524
+ alias left_of before
525
+
526
+ def after(view)
527
+ constraint = Constraint.new(target.view, :left, :equal)
528
+ constraint.equals(view, :right)
529
+
530
+ target.add_constraints([constraint])
531
+ return constraint
532
+ end
533
+ alias right_of after
534
+
535
+ end
536
+ end