motion-kit 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/motion-kit-tvos/deprecated.rb +31 -0
  4. data/lib/motion-kit-tvos/dummy.rb +93 -0
  5. data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
  6. data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
  7. data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
  8. data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
  9. data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
  10. data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
  11. data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
  12. data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
  13. data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
  14. data/lib/motion-kit-tvos/ios_util.rb +24 -0
  15. data/lib/motion-kit.rb +2 -0
  16. data/lib/motion-kit/version.rb +1 -1
  17. data/spec/tvos/apply_styles_spec.rb +37 -0
  18. data/spec/tvos/autoresizing_helper_spec.rb +240 -0
  19. data/spec/tvos/calayer_spec.rb +23 -0
  20. data/spec/tvos/calculate_spec.rb +322 -0
  21. data/spec/tvos/calculator_spec.rb +31 -0
  22. data/spec/tvos/child_layouts_spec.rb +65 -0
  23. data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
  24. data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
  25. data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
  26. data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
  27. data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  28. data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
  29. data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
  30. data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
  31. data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
  32. data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
  33. data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
  34. data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
  35. data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
  36. data/spec/tvos/create_layout_spec.rb +40 -0
  37. data/spec/tvos/custom_layout_spec.rb +13 -0
  38. data/spec/tvos/custom_root_layout_spec.rb +57 -0
  39. data/spec/tvos/deferred_spec.rb +89 -0
  40. data/spec/tvos/device_helpers_spec.rb +58 -0
  41. data/spec/tvos/frame_helper_spec.rb +1160 -0
  42. data/spec/tvos/layer_layout_spec.rb +36 -0
  43. data/spec/tvos/layout_extensions_spec.rb +70 -0
  44. data/spec/tvos/layout_spec.rb +57 -0
  45. data/spec/tvos/layout_state_spec.rb +27 -0
  46. data/spec/tvos/memory_leak_spec.rb +74 -0
  47. data/spec/tvos/motion_kit_id_spec.rb +15 -0
  48. data/spec/tvos/motionkit_util_spec.rb +15 -0
  49. data/spec/tvos/nearest_spec.rb +80 -0
  50. data/spec/tvos/objc_selectors_spec.rb +10 -0
  51. data/spec/tvos/orientation_helper_specs.rb +67 -0
  52. data/spec/tvos/parent_layout_spec.rb +19 -0
  53. data/spec/tvos/parent_spec.rb +45 -0
  54. data/spec/tvos/prev_next_spec.rb +153 -0
  55. data/spec/tvos/reapply_frame.rb +64 -0
  56. data/spec/tvos/relative_layout.spec.rb +31 -0
  57. data/spec/tvos/remove_layout_spec.rb +28 -0
  58. data/spec/tvos/root_layout_spec.rb +53 -0
  59. data/spec/tvos/setters_spec.rb +63 -0
  60. data/spec/tvos/uibutton_layout_spec.rb +37 -0
  61. data/spec/tvos/uitextfield_spec.rb +14 -0
  62. data/spec/tvos/view_attr_spec.rb +32 -0
  63. metadata +118 -8
@@ -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,65 @@
1
+ describe 'Child Layouts' do
2
+
3
+ before do
4
+ @layout = TestChildrenLayout.new.build
5
+ end
6
+
7
+ it 'should have 3 child layouts' do
8
+ @layout.child_layouts.length.should == 3
9
+ end
10
+
11
+ it 'should have a layout named :child_button' do
12
+ @layout.get(:child_button).should.be.kind_of(ChildButtonLayout)
13
+ end
14
+
15
+ it ':child_button layout should have a view named :button' do
16
+ @layout.get(:child_button).get(:button).should.be.kind_of(UIButton)
17
+ end
18
+
19
+ it 'should have a layout named :child_image' do
20
+ @layout.get(:child_image).should.be.kind_of(ChildImageLayout)
21
+ end
22
+
23
+ it ':child_image layout should have a view named :image' do
24
+ @layout.get(:child_image).get(:image).should.be.kind_of(UIImageView)
25
+ end
26
+
27
+ it 'should have initial styles on :label' do
28
+ @layout.get(:label).text.should == 'root foo'
29
+ end
30
+
31
+ it 'should apply tag on :label' do
32
+ @layout.get(:label).tag.should == 100
33
+ end
34
+
35
+ describe 'Calling reapply! on parent layout' do
36
+
37
+ before do
38
+ @layout.reapply!
39
+ end
40
+
41
+ it 'should reapply :label on root' do
42
+ @layout.get(:label).text.should == 'root reapplied'
43
+ end
44
+
45
+ it 'should apply tag on :label' do
46
+ @layout.get(:label).tag.should == 100
47
+ end
48
+
49
+ it 'should reapply :label on child layout' do
50
+ @layout.child_layouts[0].get(:label).text.should == 'reapplied'
51
+ end
52
+
53
+ it 'should reapply :button on child layout' do
54
+ @layout.get(:child_button).reapply!
55
+ @layout.get(:child_button).get(:button).currentTitle.should == 'reapplied'
56
+ end
57
+
58
+ it 'should reapply :image on child layout' do
59
+ reapplied_image = @layout.get(:child_image).reapplied_image
60
+ @layout.get(:child_image).get(:image).image.should == reapplied_image
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,25 @@
1
+ describe 'Constraints - activate/deactivate helpers' do
2
+
3
+ before do
4
+ @layout = MotionKit::Layout.new
5
+ @constraint = nil
6
+ @view = UIView.new
7
+ end
8
+
9
+ should 'should activate/deactivate constraints' do
10
+
11
+ @layout.context(@view) do
12
+ @layout.constraints do
13
+ @constraint = @layout.height(10)
14
+ end
15
+ end
16
+
17
+ @view.constraints.count.should == 1
18
+ @constraint.deactivate
19
+ @view.constraints.count.should == 0
20
+ @constraint.activate
21
+ @view.constraints.count.should == 1
22
+
23
+ end
24
+
25
+ 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,421 @@
1
+ describe 'Constraints - Center helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @constraint = nil
6
+ @view = UIView.new
7
+ @parent_view = UIView.new
8
+ @parent_view.addSubview(@view)
9
+ @another_view = nil
10
+ end
11
+
12
+ it 'should support `center [10, 10]`' do
13
+ @layout.context(@view) do
14
+ @layout.constraints do
15
+ @constraint = @layout.center([10, 10])
16
+ end
17
+ end
18
+
19
+ @constraint.constant.should == [10, 10]
20
+ @constraint.relationship.should == :equal
21
+ @constraint.multiplier.should == [1, 1]
22
+ @constraint.relative_to.should == :superview
23
+ @constraint.attribute.should == [:center_x, :center_y]
24
+ @constraint.attribute2.should == [:center_x, :center_y]
25
+
26
+ resolved = @constraint.resolve_all(@layout, @view)
27
+ resolved.length.should == 2
28
+ resolved[0].firstItem.should == @view
29
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
30
+ resolved[0].relation.should == NSLayoutRelationEqual
31
+ resolved[0].secondItem.should == @parent_view
32
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
33
+ resolved[0].multiplier.should == 1
34
+ resolved[0].constant.should == 10
35
+
36
+ resolved[1].firstItem.should == @view
37
+ resolved[1].firstAttribute.should == NSLayoutAttributeCenterY
38
+ resolved[1].relation.should == NSLayoutRelationEqual
39
+ resolved[1].secondItem.should == @parent_view
40
+ resolved[1].secondAttribute.should == NSLayoutAttributeCenterY
41
+ resolved[1].multiplier.should == 1
42
+ resolved[1].constant.should == 10
43
+ end
44
+ it 'should support `min_center [10, 10]`' do
45
+ @layout.context(@view) do
46
+ @layout.constraints do
47
+ @constraint = @layout.min_center([10, 10])
48
+ end
49
+ end
50
+
51
+ @constraint.constant.should == [10, 10]
52
+ @constraint.relationship.should == :gte
53
+ @constraint.multiplier.should == [1, 1]
54
+ @constraint.relative_to.should == :superview
55
+ @constraint.attribute.should == [:center_x, :center_y]
56
+ @constraint.attribute2.should == [:center_x, :center_y]
57
+ end
58
+ it 'should support `max_center [10, 10]`' do
59
+ @layout.context(@view) do
60
+ @layout.constraints do
61
+ @constraint = @layout.max_center([10, 10])
62
+ end
63
+ end
64
+
65
+ @constraint.constant.should == [10, 10]
66
+ @constraint.relationship.should == :lte
67
+ @constraint.multiplier.should == [1, 1]
68
+ @constraint.relative_to.should == :superview
69
+ @constraint.attribute.should == [:center_x, :center_y]
70
+ @constraint.attribute2.should == [:center_x, :center_y]
71
+ end
72
+ it 'should support `center x: 10, y: 10`' do
73
+ @layout.context(@view) do
74
+ @layout.constraints do
75
+ @constraint = @layout.center(x: 10, y: 10)
76
+ end
77
+ end
78
+
79
+ @constraint.constant.should == [10, 10]
80
+ @constraint.relationship.should == :equal
81
+ @constraint.multiplier.should == [1, 1]
82
+ @constraint.relative_to.should == :superview
83
+ @constraint.attribute.should == [:center_x, :center_y]
84
+ @constraint.attribute2.should == [:center_x, :center_y]
85
+ end
86
+ it 'should support `min_center x: 10, y: 10`' do
87
+ @layout.context(@view) do
88
+ @layout.constraints do
89
+ @constraint = @layout.min_center(x: 10, y: 10)
90
+ end
91
+ end
92
+
93
+ @constraint.constant.should == [10, 10]
94
+ @constraint.relationship.should == :gte
95
+ @constraint.multiplier.should == [1, 1]
96
+ @constraint.relative_to.should == :superview
97
+ @constraint.attribute.should == [:center_x, :center_y]
98
+ @constraint.attribute2.should == [:center_x, :center_y]
99
+ end
100
+ it 'should support `max_center x: 10, y: 10`' do
101
+ @layout.context(@view) do
102
+ @layout.constraints do
103
+ @constraint = @layout.max_center(x: 10, y: 10)
104
+ end
105
+ end
106
+
107
+ @constraint.constant.should == [10, 10]
108
+ @constraint.relationship.should == :lte
109
+ @constraint.multiplier.should == [1, 1]
110
+ @constraint.relative_to.should == :superview
111
+ @constraint.attribute.should == [:center_x, :center_y]
112
+ @constraint.attribute2.should == [:center_x, :center_y]
113
+ end
114
+ it 'should support `center.equals(:another_view[, :center])`' do
115
+ @top = @layout.context(@view) do
116
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
117
+ @layout.constraints do
118
+ @constraint = @layout.center.equals(:another_view)
119
+ end
120
+ end
121
+
122
+ @constraint.constant.should == [0, 0]
123
+ @constraint.relationship.should == :equal
124
+ @constraint.multiplier.should == [1, 1]
125
+ @constraint.relative_to.should == :another_view
126
+ @constraint.attribute.should == [:center_x, :center_y]
127
+ @constraint.attribute2.should == [:center_x, :center_y]
128
+ end
129
+ it 'should support `center.equals(:another_view).plus(10).plus([5, 10])`' do
130
+ @layout.context(@view) do
131
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
132
+ @layout.constraints do
133
+ @constraint = @layout.center.equals(:another_view).plus(10).plus([5, 10])
134
+ end
135
+ end
136
+
137
+ @constraint.constant.should == [15, 20]
138
+ @constraint.relationship.should == :equal
139
+ @constraint.multiplier.should == [1, 1]
140
+ @constraint.relative_to.should == :another_view
141
+ @constraint.attribute.should == [:center_x, :center_y]
142
+ @constraint.attribute2.should == [:center_x, :center_y]
143
+ end
144
+ it 'should support `min_center.equals(:another_view[, :center])`' do
145
+ @layout.context(@view) do
146
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
147
+ @layout.constraints do
148
+ @constraint = @layout.min_center.equals(:another_view)
149
+ end
150
+ end
151
+
152
+ @constraint.constant.should == [0, 0]
153
+ @constraint.relationship.should == :gte
154
+ @constraint.multiplier.should == [1, 1]
155
+ @constraint.relative_to.should == :another_view
156
+ @constraint.attribute.should == [:center_x, :center_y]
157
+ @constraint.attribute2.should == [:center_x, :center_y]
158
+
159
+ resolved = @constraint.resolve_all(@layout, @view)
160
+ resolved.length.should == 2
161
+ resolved[0].firstItem.should == @view
162
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
163
+ resolved[0].relation.should == NSLayoutRelationGreaterThanOrEqual
164
+ resolved[0].secondItem.should == @another_view
165
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
166
+ resolved[0].multiplier.should == 1
167
+ resolved[0].constant.should == 0
168
+
169
+ resolved[1].firstItem.should == @view
170
+ resolved[1].firstAttribute.should == NSLayoutAttributeCenterY
171
+ resolved[1].relation.should == NSLayoutRelationGreaterThanOrEqual
172
+ resolved[1].secondItem.should == @another_view
173
+ resolved[1].secondAttribute.should == NSLayoutAttributeCenterY
174
+ resolved[1].multiplier.should == 1
175
+ resolved[1].constant.should == 0
176
+ end
177
+ it 'should support `max_center.equals(:another_view[, :center])`' do
178
+ @layout.context(@view) do
179
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
180
+ @layout.constraints do
181
+ @constraint = @layout.max_center.equals(:another_view)
182
+ end
183
+ end
184
+
185
+ @constraint.constant.should == [0, 0]
186
+ @constraint.relationship.should == :lte
187
+ @constraint.multiplier.should == [1, 1]
188
+ @constraint.relative_to.should == :another_view
189
+ @constraint.attribute.should == [:center_x, :center_y]
190
+ @constraint.attribute2.should == [:center_x, :center_y]
191
+ end
192
+ it 'should support `center.equals(:another_view).plus(10)`' do
193
+ @layout.context(@view) do
194
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
195
+ @layout.constraints do
196
+ @constraint = @layout.center.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 == [:center_x, :center_y]
205
+ @constraint.attribute2.should == [:center_x, :center_y]
206
+ end
207
+ it 'should support `min_center.equals(:another_view).plus(10)`' do
208
+ @layout.context(@view) do
209
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
210
+ @layout.constraints do
211
+ @constraint = @layout.min_center.equals(:another_view).plus(10)
212
+ end
213
+ end
214
+
215
+ @constraint.constant.should == [10, 10]
216
+ @constraint.relationship.should == :gte
217
+ @constraint.multiplier.should == [1, 1]
218
+ @constraint.relative_to.should == :another_view
219
+ @constraint.attribute.should == [:center_x, :center_y]
220
+ @constraint.attribute2.should == [:center_x, :center_y]
221
+ end
222
+ it 'should support `max_center.equals(:another_view).plus(10)`' do
223
+ @layout.context(@view) do
224
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
225
+ @layout.constraints do
226
+ @constraint = @layout.max_center.equals(:another_view).plus(10)
227
+ end
228
+ end
229
+
230
+ @constraint.constant.should == [10, 10]
231
+ @constraint.relationship.should == :lte
232
+ @constraint.multiplier.should == [1, 1]
233
+ @constraint.relative_to.should == :another_view
234
+ @constraint.attribute.should == [:center_x, :center_y]
235
+ @constraint.attribute2.should == [:center_x, :center_y]
236
+ end
237
+ it 'should support `center.equals(:another_view).plus([10, 10])`' do
238
+ @layout.context(@view) do
239
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
240
+ @layout.constraints do
241
+ @constraint = @layout.center.equals(:another_view).plus([10, 10])
242
+ end
243
+ end
244
+
245
+ @constraint.constant.should == [10, 10]
246
+ @constraint.relationship.should == :equal
247
+ @constraint.multiplier.should == [1, 1]
248
+ @constraint.relative_to.should == :another_view
249
+ @constraint.attribute.should == [:center_x, :center_y]
250
+ @constraint.attribute2.should == [:center_x, :center_y]
251
+ end
252
+ it 'should support `min_center.equals(:another_view).plus([10, 10])`' do
253
+ @layout.context(@view) do
254
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
255
+ @layout.constraints do
256
+ @constraint = @layout.min_center.equals(:another_view).plus([10, 10])
257
+ end
258
+ end
259
+
260
+ @constraint.constant.should == [10, 10]
261
+ @constraint.relationship.should == :gte
262
+ @constraint.multiplier.should == [1, 1]
263
+ @constraint.relative_to.should == :another_view
264
+ @constraint.attribute.should == [:center_x, :center_y]
265
+ @constraint.attribute2.should == [:center_x, :center_y]
266
+ end
267
+ it 'should support `max_center.equals(:another_view).plus(x: 10, y: 10)`' do
268
+ @layout.context(@view) do
269
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
270
+ @layout.constraints do
271
+ @constraint = @layout.max_center.equals(:another_view).plus(x: 10, y: 10)
272
+ end
273
+ end
274
+
275
+ @constraint.constant.should == [10, 10]
276
+ @constraint.relationship.should == :lte
277
+ @constraint.multiplier.should == [1, 1]
278
+ @constraint.relative_to.should == :another_view
279
+ @constraint.attribute.should == [:center_x, :center_y]
280
+ @constraint.attribute2.should == [:center_x, :center_y]
281
+ end
282
+ it 'should support `center.equals(:another_view).times(2).plus(10)`' do
283
+ @layout.context(@view) do
284
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
285
+ @layout.constraints do
286
+ @constraint = @layout.center.equals(:another_view).times(2).plus(10)
287
+ end
288
+ end
289
+
290
+ @constraint.constant.should == [10, 10]
291
+ @constraint.relationship.should == :equal
292
+ @constraint.multiplier.should == [2, 2]
293
+ @constraint.relative_to.should == :another_view
294
+ @constraint.attribute.should == [:center_x, :center_y]
295
+ @constraint.attribute2.should == [:center_x, :center_y]
296
+ end
297
+ it 'should support `min_center.equals(:another_view).times(2).plus(10)`' do
298
+ @layout.context(@view) do
299
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
300
+ @layout.constraints do
301
+ @constraint = @layout.min_center.equals(:another_view).times(2).plus(10)
302
+ end
303
+ end
304
+
305
+ @constraint.constant.should == [10, 10]
306
+ @constraint.relationship.should == :gte
307
+ @constraint.multiplier.should == [2, 2]
308
+ @constraint.relative_to.should == :another_view
309
+ @constraint.attribute.should == [:center_x, :center_y]
310
+ @constraint.attribute2.should == [:center_x, :center_y]
311
+ end
312
+ it 'should support `max_center.equals(:another_view).times(2).plus(10)`' do
313
+ @layout.context(@view) do
314
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
315
+ @layout.constraints do
316
+ @constraint = @layout.max_center.equals(:another_view).times(2).plus(10)
317
+ end
318
+ end
319
+
320
+ @constraint.constant.should == [10, 10]
321
+ @constraint.relationship.should == :lte
322
+ @constraint.multiplier.should == [2, 2]
323
+ @constraint.relative_to.should == :another_view
324
+ @constraint.attribute.should == [:center_x, :center_y]
325
+ @constraint.attribute2.should == [:center_x, :center_y]
326
+
327
+ resolved = @constraint.resolve_all(@layout, @view)
328
+ resolved.length.should == 2
329
+ resolved[0].firstItem.should == @view
330
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
331
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
332
+ resolved[0].secondItem.should == @another_view
333
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
334
+ resolved[0].multiplier.should == 2
335
+ resolved[0].constant.should == 10
336
+
337
+ resolved[1].firstItem.should == @view
338
+ resolved[1].firstAttribute.should == NSLayoutAttributeCenterY
339
+ resolved[1].relation.should == NSLayoutRelationLessThanOrEqual
340
+ resolved[1].secondItem.should == @another_view
341
+ resolved[1].secondAttribute.should == NSLayoutAttributeCenterY
342
+ resolved[1].multiplier.should == 2
343
+ resolved[1].constant.should == 10
344
+ end
345
+ it 'should support `center.equals(:another_view).times([2, 2]).plus(10)`' do
346
+ @layout.context(@view) do
347
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
348
+ @layout.constraints do
349
+ @constraint = @layout.center.equals(:another_view).times([2, 2]).plus(10)
350
+ end
351
+ end
352
+
353
+ @constraint.constant.should == [10, 10]
354
+ @constraint.relationship.should == :equal
355
+ @constraint.multiplier.should == [2, 2]
356
+ @constraint.relative_to.should == :another_view
357
+ @constraint.attribute.should == [:center_x, :center_y]
358
+ @constraint.attribute2.should == [:center_x, :center_y]
359
+ end
360
+ it 'should support `min_center.equals(:another_view).times([2, 2]).plus(10)`' do
361
+ @layout.context(@view) do
362
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
363
+ @layout.constraints do
364
+ @constraint = @layout.min_center.equals(:another_view).times([2, 2]).plus(10)
365
+ end
366
+ end
367
+
368
+ @constraint.constant.should == [10, 10]
369
+ @constraint.relationship.should == :gte
370
+ @constraint.multiplier.should == [2, 2]
371
+ @constraint.relative_to.should == :another_view
372
+ @constraint.attribute.should == [:center_x, :center_y]
373
+ @constraint.attribute2.should == [:center_x, :center_y]
374
+ end
375
+ it 'should support `max_center.equals(:another_view).times(x: 2, y: 2).plus(10)`' do
376
+ @layout.context(@view) do
377
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
378
+ @layout.constraints do
379
+ @constraint = @layout.max_center.equals(:another_view).times(x: 2, y: 2).plus(10)
380
+ end
381
+ end
382
+
383
+ @constraint.constant.should == [10, 10]
384
+ @constraint.relationship.should == :lte
385
+ @constraint.multiplier.should == [2, 2]
386
+ @constraint.relative_to.should == :another_view
387
+ @constraint.attribute.should == [:center_x, :center_y]
388
+ @constraint.attribute2.should == [:center_x, :center_y]
389
+ end
390
+ it 'should support `center.equals(:another_view).times(2).times([3, 4])`' do
391
+ @layout.context(@view) do
392
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
393
+ @layout.constraints do
394
+ @constraint = @layout.center.equals(:another_view).times(2).times([3, 4])
395
+ end
396
+ end
397
+
398
+ @constraint.constant.should == [0, 0]
399
+ @constraint.relationship.should == :equal
400
+ @constraint.multiplier.should == [6, 8]
401
+ @constraint.relative_to.should == :another_view
402
+ @constraint.attribute.should == [:center_x, :center_y]
403
+ @constraint.attribute2.should == [:center_x, :center_y]
404
+ end
405
+ it 'should support `center.equals(:another_view).divided_by(2)`' do
406
+ @layout.context(@view) do
407
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
408
+ @layout.constraints do
409
+ @constraint = @layout.center.equals(:another_view).divided_by(2)
410
+ end
411
+ end
412
+
413
+ @constraint.constant.should == [0, 0]
414
+ @constraint.relationship.should == :equal
415
+ @constraint.multiplier.should == [0.5, 0.5]
416
+ @constraint.relative_to.should == :another_view
417
+ @constraint.attribute.should == [:center_x, :center_y]
418
+ @constraint.attribute2.should == [:center_x, :center_y]
419
+ end
420
+
421
+ end