motion-kit 0.0.1 → 0.9.0

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.
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,422 @@
1
+ describe 'Constraints - Size helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @constraint = nil
6
+ @superview = nil
7
+ @view = nil
8
+ @another_view = nil
9
+ end
10
+
11
+ it 'should support `size 10`' do
12
+ @view = @layout.context(UIView.new) do
13
+ @layout.constraints do
14
+ @constraint = @layout.size(10)
15
+ end
16
+ end
17
+
18
+ @constraint.constant.should == [10, 10]
19
+ @constraint.relationship.should == :equal
20
+ @constraint.multiplier.should == [1, 1]
21
+ @constraint.relative_to.should == nil
22
+ @constraint.attribute.should == [:width, :height]
23
+ @constraint.attribute2.should == [:width, :height]
24
+ end
25
+ it 'should support `min_size 10`' do
26
+ @layout.context(UIView.new) do
27
+ @layout.constraints do
28
+ @constraint = @layout.min_size(10)
29
+ end
30
+ end
31
+
32
+ @constraint.constant.should == [10, 10]
33
+ @constraint.relationship.should == :gte
34
+ @constraint.multiplier.should == [1, 1]
35
+ @constraint.relative_to.should == nil
36
+ @constraint.attribute.should == [:width, :height]
37
+ @constraint.attribute2.should == [:width, :height]
38
+ end
39
+ it 'should support `max_size 10`' do
40
+ @layout.context(UIView.new) do
41
+ @layout.constraints do
42
+ @constraint = @layout.max_size(10)
43
+ end
44
+ end
45
+
46
+ @constraint.constant.should == [10, 10]
47
+ @constraint.relationship.should == :lte
48
+ @constraint.multiplier.should == [1, 1]
49
+ @constraint.relative_to.should == nil
50
+ @constraint.attribute.should == [:width, :height]
51
+ @constraint.attribute2.should == [:width, :height]
52
+ end
53
+ it 'should support `size [10, 10]`' do
54
+ @layout.context(UIView.new) do
55
+ @layout.constraints do
56
+ @constraint = @layout.size([10, 10])
57
+ end
58
+ end
59
+
60
+ @constraint.constant.should == [10, 10]
61
+ @constraint.relationship.should == :equal
62
+ @constraint.multiplier.should == [1, 1]
63
+ @constraint.relative_to.should == nil
64
+ @constraint.attribute.should == [:width, :height]
65
+ @constraint.attribute2.should == [:width, :height]
66
+ end
67
+ it 'should support `min_size [10, 10]`' do
68
+ @layout.context(UIView.new) do
69
+ @layout.constraints do
70
+ @constraint = @layout.min_size([10, 10])
71
+ end
72
+ end
73
+
74
+ @constraint.constant.should == [10, 10]
75
+ @constraint.relationship.should == :gte
76
+ @constraint.multiplier.should == [1, 1]
77
+ @constraint.relative_to.should == nil
78
+ @constraint.attribute.should == [:width, :height]
79
+ @constraint.attribute2.should == [:width, :height]
80
+ end
81
+ it 'should support `max_size [10, 10]`' do
82
+ @layout.context(UIView.new) do
83
+ @layout.constraints do
84
+ @constraint = @layout.max_size([10, 10])
85
+ end
86
+ end
87
+
88
+ @constraint.constant.should == [10, 10]
89
+ @constraint.relationship.should == :lte
90
+ @constraint.multiplier.should == [1, 1]
91
+ @constraint.relative_to.should == nil
92
+ @constraint.attribute.should == [:width, :height]
93
+ @constraint.attribute2.should == [:width, :height]
94
+ end
95
+ it 'should support `size w: 10, h: 10`' do
96
+ @layout.context(UIView.new) do
97
+ @layout.constraints do
98
+ @constraint = @layout.size(w: 10, h: 10)
99
+ end
100
+ end
101
+
102
+ @constraint.constant.should == [10, 10]
103
+ @constraint.relationship.should == :equal
104
+ @constraint.multiplier.should == [1, 1]
105
+ @constraint.relative_to.should == nil
106
+ @constraint.attribute.should == [:width, :height]
107
+ @constraint.attribute2.should == [:width, :height]
108
+ end
109
+ it 'should support `min_size w: 10, h: 10`' do
110
+ @layout.context(UIView.new) do
111
+ @layout.constraints do
112
+ @constraint = @layout.min_size(w: 10, h: 10)
113
+ end
114
+ end
115
+
116
+ @constraint.constant.should == [10, 10]
117
+ @constraint.relationship.should == :gte
118
+ @constraint.multiplier.should == [1, 1]
119
+ @constraint.relative_to.should == nil
120
+ @constraint.attribute.should == [:width, :height]
121
+ @constraint.attribute2.should == [:width, :height]
122
+ end
123
+ it 'should support `max_size w: 10, h: 10`' do
124
+ @layout.context(UIView.new) do
125
+ @layout.constraints do
126
+ @constraint = @layout.max_size(w: 10, h: 10)
127
+ end
128
+ end
129
+
130
+ @constraint.constant.should == [10, 10]
131
+ @constraint.relationship.should == :lte
132
+ @constraint.multiplier.should == [1, 1]
133
+ @constraint.relative_to.should == nil
134
+ @constraint.attribute.should == [:width, :height]
135
+ @constraint.attribute2.should == [:width, :height]
136
+ end
137
+ it 'should support `size.equals(:another_view[, :size])`' do
138
+ @layout.context(UIView.new) do
139
+ @layout.constraints do
140
+ @constraint = @layout.size.equals(:another_view)
141
+ end
142
+ end
143
+
144
+ @constraint.constant.should == [0, 0]
145
+ @constraint.relationship.should == :equal
146
+ @constraint.multiplier.should == [1, 1]
147
+ @constraint.relative_to.should == :another_view
148
+ @constraint.attribute.should == [:width, :height]
149
+ @constraint.attribute2.should == [:width, :height]
150
+ end
151
+ it 'should support `size.equals(:another_view).plus(10).plus([5, 10])`' do
152
+ @layout.context(UIView.new) do
153
+ @layout.constraints do
154
+ @constraint = @layout.size.equals(:another_view).plus(10).plus([5, 10])
155
+ end
156
+ end
157
+
158
+ @constraint.constant.should == [15, 20]
159
+ @constraint.relationship.should == :equal
160
+ @constraint.multiplier.should == [1, 1]
161
+ @constraint.relative_to.should == :another_view
162
+ @constraint.attribute.should == [:width, :height]
163
+ @constraint.attribute2.should == [:width, :height]
164
+ end
165
+ it 'should support `min_size.equals(:another_view[, :size])`' do
166
+ @layout.context(UIView.new) do
167
+ @layout.constraints do
168
+ @constraint = @layout.min_size.equals(:another_view)
169
+ end
170
+ end
171
+
172
+ @constraint.constant.should == [0, 0]
173
+ @constraint.relationship.should == :gte
174
+ @constraint.multiplier.should == [1, 1]
175
+ @constraint.relative_to.should == :another_view
176
+ @constraint.attribute.should == [:width, :height]
177
+ @constraint.attribute2.should == [:width, :height]
178
+ end
179
+ it 'should support `max_size.equals(:another_view[, :size])`' do
180
+ @layout.context(UIView.new) do
181
+ @layout.constraints do
182
+ @constraint = @layout.max_size.equals(:another_view)
183
+ end
184
+ end
185
+
186
+ @constraint.constant.should == [0, 0]
187
+ @constraint.relationship.should == :lte
188
+ @constraint.multiplier.should == [1, 1]
189
+ @constraint.relative_to.should == :another_view
190
+ @constraint.attribute.should == [:width, :height]
191
+ @constraint.attribute2.should == [:width, :height]
192
+ end
193
+ it 'should support `size.equals(:another_view).plus(10)`' do
194
+ @layout.context(UIView.new) do
195
+ @layout.constraints do
196
+ @constraint = @layout.size.equals(:another_view).plus(10)
197
+ end
198
+ end
199
+
200
+ @constraint.constant.should == [10, 10]
201
+ @constraint.relationship.should == :equal
202
+ @constraint.multiplier.should == [1, 1]
203
+ @constraint.relative_to.should == :another_view
204
+ @constraint.attribute.should == [:width, :height]
205
+ @constraint.attribute2.should == [:width, :height]
206
+ end
207
+ it 'should support `min_size.equals(:another_view).plus(10)`' do
208
+ @layout.context(UIView.new) do
209
+ @layout.constraints do
210
+ @constraint = @layout.min_size.equals(:another_view).plus(10)
211
+ end
212
+ end
213
+
214
+ @constraint.constant.should == [10, 10]
215
+ @constraint.relationship.should == :gte
216
+ @constraint.multiplier.should == [1, 1]
217
+ @constraint.relative_to.should == :another_view
218
+ @constraint.attribute.should == [:width, :height]
219
+ @constraint.attribute2.should == [:width, :height]
220
+ end
221
+ it 'should support `max_size.equals(:another_view).plus(10)`' do
222
+ @layout.context(UIView.new) do
223
+ @layout.constraints do
224
+ @constraint = @layout.max_size.equals(:another_view).plus(10)
225
+ end
226
+ end
227
+
228
+ @constraint.constant.should == [10, 10]
229
+ @constraint.relationship.should == :lte
230
+ @constraint.multiplier.should == [1, 1]
231
+ @constraint.relative_to.should == :another_view
232
+ @constraint.attribute.should == [:width, :height]
233
+ @constraint.attribute2.should == [:width, :height]
234
+ end
235
+ it 'should support `size.equals(:another_view).plus([10, 10])`' do
236
+ @layout.context(UIView.new) do
237
+ @layout.constraints do
238
+ @constraint = @layout.size.equals(:another_view).plus([10, 10])
239
+ end
240
+ end
241
+
242
+ @constraint.constant.should == [10, 10]
243
+ @constraint.relationship.should == :equal
244
+ @constraint.multiplier.should == [1, 1]
245
+ @constraint.relative_to.should == :another_view
246
+ @constraint.attribute.should == [:width, :height]
247
+ @constraint.attribute2.should == [:width, :height]
248
+ end
249
+ it 'should support `min_size.equals(:another_view).plus([10, 10])`' do
250
+ @layout.context(UIView.new) do
251
+ @layout.constraints do
252
+ @constraint = @layout.min_size.equals(:another_view).plus([10, 10])
253
+ end
254
+ end
255
+
256
+ @constraint.constant.should == [10, 10]
257
+ @constraint.relationship.should == :gte
258
+ @constraint.multiplier.should == [1, 1]
259
+ @constraint.relative_to.should == :another_view
260
+ @constraint.attribute.should == [:width, :height]
261
+ @constraint.attribute2.should == [:width, :height]
262
+ end
263
+ it 'should support `max_size.equals(:another_view).plus(w: 10, h: 10)`' do
264
+ @layout.context(UIView.new) do
265
+ @layout.constraints do
266
+ @constraint = @layout.max_size.equals(:another_view).plus(w: 10, h: 10)
267
+ end
268
+ end
269
+
270
+ @constraint.constant.should == [10, 10]
271
+ @constraint.relationship.should == :lte
272
+ @constraint.multiplier.should == [1, 1]
273
+ @constraint.relative_to.should == :another_view
274
+ @constraint.attribute.should == [:width, :height]
275
+ @constraint.attribute2.should == [:width, :height]
276
+ end
277
+ it 'should support `size.equals(:another_view).times(2).plus(10)`' do
278
+ @layout.context(UIView.new) do
279
+ @layout.constraints do
280
+ @constraint = @layout.size.equals(:another_view).times(2).plus(10)
281
+ end
282
+ end
283
+
284
+ @constraint.constant.should == [10, 10]
285
+ @constraint.relationship.should == :equal
286
+ @constraint.multiplier.should == [2, 2]
287
+ @constraint.relative_to.should == :another_view
288
+ @constraint.attribute.should == [:width, :height]
289
+ @constraint.attribute2.should == [:width, :height]
290
+ end
291
+ it 'should support `min_size.equals(:another_view).times(2).plus(10)`' do
292
+ @layout.context(UIView.new) do
293
+ @layout.constraints do
294
+ @constraint = @layout.min_size.equals(:another_view).times(2).plus(10)
295
+ end
296
+ end
297
+
298
+ @constraint.constant.should == [10, 10]
299
+ @constraint.relationship.should == :gte
300
+ @constraint.multiplier.should == [2, 2]
301
+ @constraint.relative_to.should == :another_view
302
+ @constraint.attribute.should == [:width, :height]
303
+ @constraint.attribute2.should == [:width, :height]
304
+ end
305
+ it 'should support `max_size.equals(:another_view).times(2).plus(10)`' do
306
+ @layout.context(UIView.new) do
307
+ @layout.constraints do
308
+ @constraint = @layout.max_size.equals(:another_view).times(2).plus(10)
309
+ end
310
+ end
311
+
312
+ @constraint.constant.should == [10, 10]
313
+ @constraint.relationship.should == :lte
314
+ @constraint.multiplier.should == [2, 2]
315
+ @constraint.relative_to.should == :another_view
316
+ @constraint.attribute.should == [:width, :height]
317
+ @constraint.attribute2.should == [:width, :height]
318
+ end
319
+ it 'should support `max_size("50%")`' do
320
+ @superview = @layout.context(UIView.new) do
321
+ @view = @layout.add(UIView.new) do
322
+ @layout.constraints do
323
+ @constraint = @layout.max_size('50%')
324
+ end
325
+ end
326
+ end
327
+
328
+ @constraint.constant.should == [0, 0]
329
+ @constraint.relationship.should == :lte
330
+ @constraint.multiplier.should == [0.5, 0.5]
331
+ @constraint.relative_to.should == nil
332
+ @constraint.attribute.should == [:width, :height]
333
+ @constraint.attribute2.should == [:width, :height]
334
+ end
335
+ it 'should support `max_size("50% + 1").of(:another_view)`' do
336
+ @superview = @layout.context(UIView.new) do
337
+ @view = @layout.add(UIView.new) do
338
+ @layout.constraints do
339
+ @constraint = @layout.max_size('50% + 1').of(:another_view)
340
+ end
341
+ end
342
+ end
343
+
344
+ @constraint.constant.should == [1, 1]
345
+ @constraint.relationship.should == :lte
346
+ @constraint.multiplier.should == [0.5, 0.5]
347
+ @constraint.relative_to.should == :another_view
348
+ @constraint.attribute.should == [:width, :height]
349
+ @constraint.attribute2.should == [:width, :height]
350
+ end
351
+ it 'should support `size.equals(:another_view).times([2, 2]).plus(10)`' do
352
+ @layout.context(UIView.new) do
353
+ @layout.constraints do
354
+ @constraint = @layout.size.equals(:another_view).times([2, 2]).plus(10)
355
+ end
356
+ end
357
+
358
+ @constraint.constant.should == [10, 10]
359
+ @constraint.relationship.should == :equal
360
+ @constraint.multiplier.should == [2, 2]
361
+ @constraint.relative_to.should == :another_view
362
+ @constraint.attribute.should == [:width, :height]
363
+ @constraint.attribute2.should == [:width, :height]
364
+ end
365
+ it 'should support `min_size.equals(:another_view).times([2, 2]).plus(10)`' do
366
+ @layout.context(UIView.new) do
367
+ @layout.constraints do
368
+ @constraint = @layout.min_size.equals(:another_view).times([2, 2]).plus(10)
369
+ end
370
+ end
371
+
372
+ @constraint.constant.should == [10, 10]
373
+ @constraint.relationship.should == :gte
374
+ @constraint.multiplier.should == [2, 2]
375
+ @constraint.relative_to.should == :another_view
376
+ @constraint.attribute.should == [:width, :height]
377
+ @constraint.attribute2.should == [:width, :height]
378
+ end
379
+ it 'should support `max_size.equals(:another_view).times(w: 2, h: 2).plus(10)`' do
380
+ @layout.context(UIView.new) do
381
+ @layout.constraints do
382
+ @constraint = @layout.max_size.equals(:another_view).times(w: 2, h: 2).plus(10)
383
+ end
384
+ end
385
+
386
+ @constraint.constant.should == [10, 10]
387
+ @constraint.relationship.should == :lte
388
+ @constraint.multiplier.should == [2, 2]
389
+ @constraint.relative_to.should == :another_view
390
+ @constraint.attribute.should == [:width, :height]
391
+ @constraint.attribute2.should == [:width, :height]
392
+ end
393
+ it 'should support `size.equals(:another_view).times(2).times([3, 4])`' do
394
+ @layout.context(UIView.new) do
395
+ @layout.constraints do
396
+ @constraint = @layout.size.equals(:another_view).times(2).times([3, 4])
397
+ end
398
+ end
399
+
400
+ @constraint.constant.should == [0, 0]
401
+ @constraint.relationship.should == :equal
402
+ @constraint.multiplier.should == [6, 8]
403
+ @constraint.relative_to.should == :another_view
404
+ @constraint.attribute.should == [:width, :height]
405
+ @constraint.attribute2.should == [:width, :height]
406
+ end
407
+ it 'should support `size.equals(:another_view).divided_by(2)`' do
408
+ @layout.context(UIView.new) do
409
+ @layout.constraints do
410
+ @constraint = @layout.size.equals(:another_view).divided_by(2)
411
+ end
412
+ end
413
+
414
+ @constraint.constant.should == [0, 0]
415
+ @constraint.relationship.should == :equal
416
+ @constraint.multiplier.should == [0.5, 0.5]
417
+ @constraint.relative_to.should == :another_view
418
+ @constraint.attribute.should == [:width, :height]
419
+ @constraint.attribute2.should == [:width, :height]
420
+ end
421
+
422
+ end
@@ -0,0 +1,93 @@
1
+ describe 'Constraints - view_lookup method' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @constraint = nil
6
+ @view = nil
7
+ @another_view = nil
8
+ end
9
+
10
+ it 'should support :superview' do
11
+ @superview = @layout.context(UIView.new) do
12
+ @view = @layout.add(UIView.new) do
13
+ @layout.constraints do
14
+ @constraint = @layout.left.equals(:superview).plus(10)
15
+ end
16
+ end
17
+ end
18
+
19
+ @constraint.constant.should == 10
20
+ @constraint.relationship.should == :equal
21
+ @constraint.multiplier.should == 1
22
+ @constraint.relative_to.should == :superview
23
+ @constraint.attribute.should == :left
24
+ @constraint.attribute2.should == :left
25
+
26
+ resolved = @constraint.resolve_all(@layout, @view)
27
+ resolved.length.should == 1
28
+ resolved[0].firstItem.should.be.kind_of(UIView)
29
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
30
+ resolved[0].relation.should == NSLayoutRelationEqual
31
+ resolved[0].secondItem.should == @superview
32
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
33
+ resolved[0].multiplier.should == 1
34
+ resolved[0].constant.should == 10
35
+ end
36
+
37
+ it 'should support :another_view' do
38
+ @superview = @layout.context(UIView.new) do
39
+ @view = @layout.add(UIView.new) do
40
+ @layout.constraints do
41
+ @constraint = @layout.left.equals(:another_view).plus(10)
42
+ end
43
+ end
44
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
45
+ end
46
+
47
+ @constraint.constant.should == 10
48
+ @constraint.relationship.should == :equal
49
+ @constraint.multiplier.should == 1
50
+ @constraint.relative_to.should == :another_view
51
+ @constraint.attribute.should == :left
52
+ @constraint.attribute2.should == :left
53
+
54
+ resolved = @constraint.resolve_all(@layout, @view)
55
+ resolved.length.should == 1
56
+ resolved[0].firstItem.should.be.kind_of(UIView)
57
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
58
+ resolved[0].relation.should == NSLayoutRelationEqual
59
+ resolved[0].secondItem.should == @another_view
60
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
61
+ resolved[0].multiplier.should == 1
62
+ resolved[0].constant.should == 10
63
+ end
64
+
65
+ it 'should support @another_view' do
66
+ @superview = @layout.context(UIView.new) do
67
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
68
+ @view = @layout.add(UIView.new) do
69
+ @layout.constraints do
70
+ @constraint = @layout.left.equals(@another_view).plus(10)
71
+ end
72
+ end
73
+ end
74
+
75
+ @constraint.constant.should == 10
76
+ @constraint.relationship.should == :equal
77
+ @constraint.multiplier.should == 1
78
+ @constraint.relative_to.should == @another_view
79
+ @constraint.attribute.should == :left
80
+ @constraint.attribute2.should == :left
81
+
82
+ resolved = @constraint.resolve_all(@layout, @view)
83
+ resolved.length.should == 1
84
+ resolved[0].firstItem.should.be.kind_of(UIView)
85
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
86
+ resolved[0].relation.should == NSLayoutRelationEqual
87
+ resolved[0].secondItem.should == @another_view
88
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
89
+ resolved[0].multiplier.should == 1
90
+ resolved[0].constant.should == 10
91
+ end
92
+
93
+ end