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