motion-kit 0.18.0 → 1.0.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 (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,40 @@
1
+ describe 'Create Layout' do
2
+ before do
3
+ @subject = TestCreateLayout.new
4
+ end
5
+
6
+ it 'should create a view' do
7
+ @subject.create_view.should.not == nil
8
+ end
9
+
10
+ it 'should create a UIView' do
11
+ @subject.create_view.should.be.kind_of(UIView)
12
+ end
13
+
14
+ it 'should create a new view every time' do
15
+ create_view1 = @subject.create_view
16
+ create_view2 = @subject.create_view
17
+ create_view1.should.not == create_view2
18
+ end
19
+
20
+ it 'should create a view without a superview' do
21
+ @subject.create_view.superview.should == nil
22
+ end
23
+
24
+ it 'should add a label to the view' do
25
+ @subject.create_view.subviews.first.should.be.kind_of(UILabel)
26
+ end
27
+
28
+ it 'should not add an image view' do
29
+ @subject.create_view.subviews.find { |view| view.is_a?(UIImageView) }.should == nil
30
+ end
31
+
32
+ it 'should allow a view to be returned ' do
33
+ @subject.create_and_context.should.not == nil
34
+ end
35
+
36
+ it 'should create a UIView via context' do
37
+ @subject.create_and_context.should.be.kind_of(UIView)
38
+ end
39
+
40
+ end
@@ -0,0 +1,13 @@
1
+ describe "Custom Layout" do
2
+
3
+ before do
4
+ @subject = TestCustomLayout.new
5
+ end
6
+
7
+ it 'should always use the correct Layout' do
8
+ @subject.view.should.be.kind_of?(CustomLabel)
9
+ @subject.view.text.should == 'custom text'
10
+ @subject.view.attributedText.should.not == nil
11
+ end
12
+
13
+ end
@@ -0,0 +1,57 @@
1
+ describe 'Custom Root Layouts' do
2
+ before do
3
+ @view = UIView.new
4
+ @subject = TestCustomRootLayout.new(root: @view)
5
+ end
6
+
7
+ it "should set the root view to the @view instance" do
8
+ @subject.view.should == @view
9
+ end
10
+
11
+ it "should still create subviews" do
12
+ @subject.view.subviews.first.should.be.kind_of UIButton
13
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UILabel
14
+ end
15
+
16
+ it "should call style method" do
17
+ @subject.view.backgroundColor.should == UIColor.blueColor
18
+ end
19
+
20
+ it "should raise exception if you try to specify a root inside the layout too" do
21
+ -> do
22
+ subject = TestCustomDuplicateRootLayout.new(root: @view)
23
+ subject.view
24
+ end.should.raise(MotionKit::ContextConflictError)
25
+ end
26
+
27
+ it "should allow multiple nested layouts" do
28
+ @subject = TestMultipleNestedLayout.new
29
+ @subject.view.backgroundColor.should == UIColor.purpleColor
30
+ @subject.view.subviews.first.should.be.kind_of TestNestedView
31
+ @subject.view.subviews.first.backgroundColor.should == UIColor.yellowColor
32
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UIButton
33
+ @subject.view.subviews.first.subviews.first.backgroundColor.should == UIColor.blackColor
34
+ end
35
+
36
+ it "shouldn't build if `build` or `view` aren't called" do
37
+ @subject.built?.should == false
38
+ end
39
+
40
+ it "should build when `build` is called" do
41
+ @subject.build
42
+ @subject.built?.should == true
43
+ end
44
+
45
+ it "should build when `view` is called" do
46
+ @subject.view
47
+ @subject.built?.should == true
48
+ end
49
+
50
+ it "should allow bare styles in layout when root is specified in initializer" do
51
+ @subject = TestNoRootLayout.new(root: @view).build
52
+ @subject.view.should == @view
53
+ @subject.view.backgroundColor.should == UIColor.redColor
54
+ @subject.view.subviews.first.should.be.kind_of?(UILabel)
55
+ end
56
+
57
+ end
@@ -0,0 +1,89 @@
1
+ describe TestDeferredLayout do
2
+
3
+ before do
4
+ @layout = TestDeferredLayout.new
5
+ @layout.view
6
+ end
7
+
8
+ describe 'from layout' do
9
+ it 'should run the deferred block' do
10
+ @layout.layout_test_ran.should == true
11
+ end
12
+
13
+ it 'should have assigned the value 0' do
14
+ @layout.layout_test_is_0.should == true
15
+ end
16
+
17
+ it 'should end up with the value 1' do
18
+ @layout.layout_test.should == 1
19
+ end
20
+ end
21
+
22
+ describe 'from create_view' do
23
+ before do
24
+ @layout.create_view
25
+ end
26
+
27
+ it 'should run the deferred block' do
28
+ @layout.create_view_test_ran.should == true
29
+ end
30
+
31
+ it 'should have assigned the value 0' do
32
+ @layout.create_view_test_is_0.should == true
33
+ end
34
+
35
+ it 'should end up with the value 1' do
36
+ @layout.create_view_test.should == 1
37
+ end
38
+ end
39
+
40
+ describe 'from error_no_context' do
41
+ it 'should raise InvalidDeferredError' do
42
+ -> do
43
+ @layout.error_no_context
44
+ end.should.raise(MK::InvalidDeferredError)
45
+ end
46
+ end
47
+
48
+ describe 'from nested_blocks' do
49
+ before do
50
+ @layout.nested_blocks
51
+ end
52
+
53
+ it 'should run the deferred block' do
54
+ @layout.nested_blocks_test_ran.should == true
55
+ end
56
+ it 'should have assigned the value 0' do
57
+ @layout.nested_blocks_test_is_0.should == true
58
+ end
59
+ it 'should have assigned the value 1' do
60
+ @layout.nested_blocks_test_is_1.should == true
61
+ end
62
+ it 'should end up with the value 1' do
63
+ @layout.nested_blocks_test.should == 2
64
+ end
65
+ end
66
+
67
+ describe 'from apply_layouts' do
68
+ before do
69
+ @layout.apply_layouts
70
+ end
71
+
72
+ it 'should run the deferred block' do
73
+ @layout.apply_layouts_test_ran.should == 3
74
+ end
75
+
76
+ it 'should have assigned text to the label' do
77
+ @layout.apply_layouts_label.text.should == 'after'
78
+ end
79
+
80
+ it 'should have assigned title to the button' do
81
+ @layout.apply_layouts_button.currentTitle.should == 'after'
82
+ end
83
+
84
+ it 'should have assigned opacity to the layer' do
85
+ @layout.apply_layouts_layer.opacity.should == 0.5
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,58 @@
1
+ describe 'Device helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ end
6
+
7
+ it 'should have device helpers' do
8
+ @layout.context({}) do
9
+ @layout.tv?.should == true
10
+ @layout.iphone?.should == false
11
+ @layout.iphone4?.should == false
12
+ @layout.iphone35?.should == false
13
+ @layout.ipad?.should == false
14
+ @layout.retina?.should == false
15
+ end
16
+ end
17
+
18
+ it 'should have device (iphone do end) helpers' do
19
+ @layout.context({}) do
20
+ @check = false
21
+ @layout.tv do
22
+ @check = true
23
+ end
24
+ @check.should == true
25
+
26
+ @check = false
27
+ @layout.iphone do
28
+ @check = true
29
+ end
30
+ @check.should == false
31
+
32
+ @check = false
33
+ @layout.iphone4 do
34
+ @check = true
35
+ end
36
+ @check.should == false
37
+
38
+ @check = false
39
+ @layout.iphone35 do
40
+ @check = true
41
+ end
42
+ @check.should == false
43
+
44
+ @check = false
45
+ @layout.ipad do
46
+ @check = true
47
+ end
48
+ @check.should == false
49
+
50
+ @check = false
51
+ @layout.retina do
52
+ @check = true
53
+ end
54
+ @check.should == false
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,1160 @@
1
+ describe 'Frame helpers' do
2
+
3
+ before do
4
+ @layout = TestEmptyLayout.new
5
+ top_view = UIView.new
6
+ @layout.root = top_view
7
+
8
+ @view_size = CGSize.new(8, 10)
9
+ @view = UIView.alloc.initWithFrame([[0, 0], @view_size])
10
+ @view.backgroundColor = UIColor.whiteColor
11
+ @layout.name_element(@view, :view)
12
+
13
+ @superview_size = CGSize.new(60, 40)
14
+ @superview = UIView.alloc.initWithFrame([[0, 0], @superview_size])
15
+ @superview.addSubview(@view)
16
+ @superview.backgroundColor = UIColor.blueColor
17
+
18
+ @another_view = UIView.alloc.initWithFrame([[10, 100], [120, 48]])
19
+ @another_view.backgroundColor = UIColor.redColor
20
+ @layout.name_element(@another_view, :another_view)
21
+
22
+ top_view.addSubview(@another_view)
23
+ top_view.addSubview(@superview)
24
+
25
+ @label = UILabel.alloc.init
26
+ @label.text = 'M'
27
+ @label_auto_size = @label.intrinsicContentSize
28
+ end
29
+
30
+ it 'should support `x` method' do
31
+ @layout.context(@view) do
32
+ retval = @layout.x 1
33
+ @view.frame.origin.x.should == 1
34
+ retval.should == CGRectGetMinX(@view.frame)
35
+
36
+ retval = @layout.x '100% - 1'
37
+ @view.frame.origin.x.should == @superview_size.width - 1
38
+ retval.should == CGRectGetMinX(@view.frame)
39
+ end
40
+ end
41
+
42
+ it 'should support `left` method' do
43
+ @layout.context(@view) do
44
+ retval = @layout.left 1
45
+ @view.frame.origin.x.should == 1
46
+ retval.should == CGRectGetMinX(@view.frame)
47
+
48
+ retval = @layout.left '100% - 1'
49
+ @view.frame.origin.x.should == @superview_size.width - 1
50
+ retval.should == CGRectGetMinX(@view.frame)
51
+ end
52
+ end
53
+
54
+ it 'should support `right` method' do
55
+ @layout.context(@view) do
56
+ retval = @layout.right 1
57
+ @view.frame.origin.x.should == 1 - @view_size.width
58
+ retval.should == CGRectGetMaxX(@view.frame)
59
+
60
+ retval = @layout.right '100% - 1'
61
+ @view.frame.origin.x.should == @superview_size.width - 1 - @view_size.width
62
+ retval.should == CGRectGetMaxX(@view.frame)
63
+ end
64
+ end
65
+
66
+ it 'should support `center_x` method' do
67
+ @view.frame = [[0, 0], [2, 2]]
68
+ @layout.context(@view) do
69
+ retval = @layout.center_x 1
70
+ @view.center.x.should == 1
71
+ retval.should == CGRectGetMidX(@view.frame)
72
+
73
+ retval = @layout.center_x '100% - 1'
74
+ @view.center.x.should == @superview_size.width - 1
75
+ retval.should == CGRectGetMidX(@view.frame)
76
+ end
77
+ end
78
+
79
+ it 'should support `middle_x` method' do
80
+ @view.frame = [[0, 0], [2, 2]]
81
+ @layout.context(@view) do
82
+ retval = @layout.middle_x 1
83
+ @view.center.x.should == 1
84
+ retval.should == CGRectGetMidX(@view.frame)
85
+
86
+ retval = @layout.middle_x '100% - 1'
87
+ @view.center.x.should == @superview_size.width - 1
88
+ retval.should == CGRectGetMidX(@view.frame)
89
+ end
90
+ end
91
+
92
+ it 'should support `y` method' do
93
+ @layout.context(@view) do
94
+ retval = @layout.y 1
95
+ @view.frame.origin.y.should == 1
96
+ retval.should == CGRectGetMinY(@view.frame)
97
+
98
+ retval = @layout.y '100% - 1'
99
+ @view.frame.origin.y.should == @superview_size.height - 1
100
+ retval.should == CGRectGetMinY(@view.frame)
101
+ end
102
+ end
103
+
104
+ it 'should support `top` method' do
105
+ @layout.context(@view) do
106
+ retval = @layout.top 1
107
+ @view.frame.origin.y.should == 1
108
+ retval.should == CGRectGetMinY(@view.frame)
109
+
110
+ retval = @layout.top '100% - 1'
111
+ @view.frame.origin.y.should == @superview_size.height - 1
112
+ retval.should == CGRectGetMinY(@view.frame)
113
+ end
114
+ end
115
+
116
+ it 'should support `bottom` method' do
117
+ @layout.context(@view) do
118
+ retval = @layout.bottom 1
119
+ @view.frame.origin.y.should == 1 - @view_size.height
120
+ retval.should == CGRectGetMaxY(@view.frame)
121
+
122
+ retval = @layout.bottom '100% - 1'
123
+ @view.frame.origin.y.should == @superview_size.height - 1 - @view_size.height
124
+ retval.should == CGRectGetMaxY(@view.frame)
125
+ end
126
+ end
127
+
128
+ it 'should support `center_y` method' do
129
+ @view.frame = [[0, 0], [2, 2]]
130
+ @layout.context(@view) do
131
+ retval = @layout.center_y 1
132
+ @view.center.y.should == 1
133
+ retval.should == CGRectGetMidY(@view.frame)
134
+
135
+ retval = @layout.center_y '100% - 1'
136
+ @view.center.y.should == @superview_size.height - 1
137
+ retval.should == CGRectGetMidY(@view.frame)
138
+ end
139
+ end
140
+
141
+ it 'should support `middle_y` method' do
142
+ @view.frame = [[0, 0], [2, 2]]
143
+ @layout.context(@view) do
144
+ retval = @layout.middle_y 1
145
+ @view.center.y.should == 1
146
+ retval.should == CGRectGetMidY(@view.frame)
147
+
148
+ retval = @layout.middle_y '100% - 1'
149
+ @view.center.y.should == @superview_size.height - 1
150
+ retval.should == CGRectGetMidY(@view.frame)
151
+ end
152
+ end
153
+
154
+ it 'should support `width` method' do
155
+ @layout.context(@view) do
156
+ retval = @layout.width 1
157
+ @view.frame.size.width.should == 1
158
+ retval.should == CGRectGetWidth(@view.frame)
159
+
160
+ retval = @layout.width '100% - 1'
161
+ @view.frame.size.width.should == @superview_size.width - 1
162
+ retval.should == CGRectGetWidth(@view.frame)
163
+ end
164
+ end
165
+
166
+ it 'should support `w` method' do
167
+ @layout.context(@view) do
168
+ retval = @layout.w 1
169
+ @view.frame.size.width.should == 1
170
+ retval.should == CGRectGetWidth(@view.frame)
171
+
172
+ retval = @layout.w '100% - 1'
173
+ @view.frame.size.width.should == @superview_size.width - 1
174
+ retval.should == CGRectGetWidth(@view.frame)
175
+ end
176
+ end
177
+
178
+ it 'should support `height` method' do
179
+ @layout.context(@view) do
180
+ retval = @layout.height 1
181
+ @view.frame.size.height.should == 1
182
+ retval.should == CGRectGetHeight(@view.frame)
183
+
184
+ retval = @layout.height '100% - 1'
185
+ @view.frame.size.height.should == @superview_size.height - 1
186
+ retval.should == CGRectGetHeight(@view.frame)
187
+ end
188
+ end
189
+
190
+ it 'should support `h` method' do
191
+ @layout.context(@view) do
192
+ retval = @layout.h 1
193
+ @view.frame.size.height.should == 1
194
+ retval.should == CGRectGetHeight(@view.frame)
195
+
196
+ retval = @layout.h '100% - 1'
197
+ @view.frame.size.height.should == @superview_size.height - 1
198
+ retval.should == CGRectGetHeight(@view.frame)
199
+ end
200
+ end
201
+
202
+ it 'should support `origin([])` method' do
203
+ @layout.context(@view) do
204
+ retval = @layout.origin [1, 2]
205
+ @view.frame.origin.x.should == 1
206
+ @view.frame.origin.y.should == 2
207
+ retval.should == @view.frame.origin
208
+
209
+ retval = @layout.origin ['100% - 1', '100% - 2']
210
+ @view.frame.origin.x.should == @superview_size.width - 1
211
+ @view.frame.origin.y.should == @superview_size.height - 2
212
+ retval.should == @view.frame.origin
213
+ end
214
+ end
215
+
216
+ it 'should support `origin({})` method' do
217
+ @layout.context(@view) do
218
+ retval = @layout.origin x: 1, y: 2
219
+ @view.frame.origin.x.should == 1
220
+ @view.frame.origin.y.should == 2
221
+ retval.should == @view.frame.origin
222
+
223
+ retval = @layout.origin x: '100% - 1', y: '100% - 2'
224
+ @view.frame.origin.x.should == @superview_size.width - 1
225
+ @view.frame.origin.y.should == @superview_size.height - 2
226
+ retval.should == @view.frame.origin
227
+ end
228
+ end
229
+
230
+ it 'should support `origin({relative: true})` method' do
231
+ @layout.context(@view) do
232
+ retval = @layout.origin right: 1, down: 2, relative: true
233
+ @view.frame.origin.x.should == 1
234
+ @view.frame.origin.y.should == 2
235
+ retval.should == @view.frame.origin
236
+
237
+ retval = @layout.origin x: '100%', y: '100%', left: 1, up: 2, relative: true
238
+ @view.frame.origin.x.should == @superview_size.width - 1
239
+ @view.frame.origin.y.should == @superview_size.height - 2
240
+ retval.should == @view.frame.origin
241
+ end
242
+ end
243
+
244
+ it 'should support `center([])` method' do
245
+ @view.frame = [[0, 0], [2, 2]]
246
+ @layout.context(@view) do
247
+ retval = @layout.center [1, 2]
248
+ @view.center.x.should == 1
249
+ @view.center.y.should == 2
250
+ retval.should == @view.center
251
+
252
+ retval = @layout.center ['100% - 1', '100% - 2']
253
+ @view.center.x.should == @superview_size.width - 1
254
+ @view.center.y.should == @superview_size.height - 2
255
+ retval.should == @view.center
256
+ end
257
+ end
258
+
259
+ it 'should support `center({})` method' do
260
+ @view.frame = [[0, 0], [2, 2]]
261
+ @layout.context(@view) do
262
+ retval = @layout.center x: 1, y: 2
263
+ @view.center.x.should == 1
264
+ @view.center.y.should == 2
265
+ retval.should == @view.center
266
+
267
+ retval = @layout.center x: '100% - 1', y: '100% - 2'
268
+ @view.center.x.should == @superview_size.width - 1
269
+ @view.center.y.should == @superview_size.height - 2
270
+ retval.should == @view.center
271
+ end
272
+ end
273
+
274
+ it 'should support `center({relative: true})` method' do
275
+ @view.frame = [[0, 0], [2, 2]]
276
+ @layout.context(@view) do
277
+ retval = @layout.center x: 1, y: 1, right: 1, down: 2, relative: true
278
+ @view.center.x.should == 2
279
+ @view.center.y.should == 3
280
+ retval.should == @view.center
281
+
282
+ retval = @layout.center x: '100%', y: '100%', left: 1, up: 2, relative: true
283
+ @view.center.x.should == @superview_size.width - 1
284
+ @view.center.y.should == @superview_size.height - 2
285
+ retval.should == @view.center
286
+ end
287
+ end
288
+
289
+ it 'should support `size` method' do
290
+ @layout.context(@view) do
291
+ retval = @layout.size [1, 2]
292
+ @view.frame.size.width.should == 1
293
+ @view.frame.size.height.should == 2
294
+ retval.should == @view.frame.size
295
+
296
+ retval = @layout.size ['100% - 1', '100% - 2']
297
+ @view.frame.size.width.should == @superview_size.width - 1
298
+ @view.frame.size.height.should == @superview_size.height - 2
299
+ retval.should == @view.frame.size
300
+ end
301
+ end
302
+
303
+ it 'should support `size :full`' do
304
+ @layout.context(@view) do
305
+ retval = @layout.size :full
306
+ retval.should == @view.frame.size
307
+ end
308
+ @view.frame.size.width.should == @superview_size.width
309
+ @view.frame.size.height.should == @superview_size.height
310
+ end
311
+
312
+ it 'should support `size :auto`' do
313
+ @layout.context(@label) do
314
+ retval = @layout.size :auto
315
+ retval.should == @label.frame.size
316
+ end
317
+ @label.frame.size.width.should == @label_auto_size.width
318
+ @label.frame.size.height.should == @label_auto_size.height
319
+ end
320
+
321
+ it 'should support `size :auto, height`' do
322
+ @layout.context(@label) do
323
+ retval = @layout.size [:auto, @label_auto_size.height]
324
+ retval.should == @label.frame.size
325
+ end
326
+ @label.frame.size.width.should == @label_auto_size.width
327
+ @label.frame.size.height.should == @label_auto_size.height
328
+ end
329
+
330
+ it 'should support `size width, :auto`' do
331
+ @layout.context(@label) do
332
+ retval = @layout.size [@label_auto_size.width, :auto]
333
+ retval.should == @label.frame.size
334
+ end
335
+ @label.frame.size.width.should == @label_auto_size.width
336
+ @label.frame.size.height.should == @label_auto_size.height
337
+ end
338
+
339
+ it 'should support `size :scale, height`' do
340
+ @layout.context(@label) do
341
+ retval = @layout.size [100 * @label_auto_size.width, :scale]
342
+ retval.should == @label.frame.size
343
+ end
344
+ @label.frame.size.width.should == 100 * @label_auto_size.width
345
+ @label.frame.size.height.should == 100 * @label_auto_size.height
346
+ end
347
+
348
+ it 'should support `size width, :scale`' do
349
+ @layout.context(@label) do
350
+ retval = @layout.size [:scale, 100 * @label_auto_size.height]
351
+ retval.should == @label.frame.size
352
+ end
353
+ @label.frame.size.width.should == 100 * @label_auto_size.width
354
+ @label.frame.size.height.should == 100 * @label_auto_size.height
355
+ end
356
+
357
+ it 'should support `frame` arrays [[x, y], [w, h]]' do
358
+ @layout.context(@view) do
359
+ retval = @layout.frame [[1, 2], [3, 4]]
360
+ retval.should == @view.frame
361
+ end
362
+ @view.frame.origin.x.should == 1
363
+ @view.frame.origin.y.should == 2
364
+ @view.frame.size.width.should == 3
365
+ @view.frame.size.height.should == 4
366
+ end
367
+
368
+ it 'should support `frame` arrays [x, y, w, h]' do
369
+ @layout.context(@view) do
370
+ retval = @layout.frame [1, 2, 3, 4]
371
+ retval.should == @view.frame
372
+ end
373
+ @view.frame.origin.x.should == 1
374
+ @view.frame.origin.y.should == 2
375
+ @view.frame.size.width.should == 3
376
+ @view.frame.size.height.should == 4
377
+ end
378
+
379
+ it 'should support `frame :full`' do
380
+ @layout.context(@view) do
381
+ retval = @layout.frame :full
382
+ retval.should == @view.frame
383
+ end
384
+ @view.frame.origin.x.should == 0
385
+ @view.frame.origin.y.should == 0
386
+ @view.frame.size.width.should == @superview_size.width
387
+ @view.frame.size.height.should == @superview_size.height
388
+ end
389
+
390
+ it 'should support `frame :auto`' do
391
+ def @view.intrinsicContentSize
392
+ CGSize.new(1, 2)
393
+ end
394
+
395
+ @layout.context(@view) do
396
+ retval = @layout.frame :auto
397
+ retval.should == @view.frame
398
+ end
399
+ @view.frame.origin.x.should == 0
400
+ @view.frame.origin.y.should == 0
401
+ @view.frame.size.width.should == 1
402
+ @view.frame.size.height.should == 2
403
+ end
404
+
405
+ it 'should support `frame :center`' do
406
+ @layout.context(@view) do
407
+ retval = @layout.frame :center
408
+ retval.should == @view.frame
409
+ end
410
+ @view.frame.origin.x.should == 26
411
+ @view.frame.origin.y.should == 15
412
+ @view.frame.size.width.should == @view_size.width
413
+ @view.frame.size.height.should == @view_size.height
414
+ end
415
+
416
+ it 'should support setting the frame via `from_top_left`' do
417
+ @layout.context(@view) do
418
+ retval = @layout.frame @layout.from_top_left()
419
+ retval.should == @view.frame
420
+ end
421
+ @view.frame.origin.x.should == 0
422
+ @view.frame.origin.y.should == 0
423
+ @view.frame.size.width.should == @view_size.width
424
+ @view.frame.size.height.should == @view_size.height
425
+ end
426
+
427
+ it 'should support setting the frame via `from_top_left(width:height:)`' do
428
+ @layout.context(@view) do
429
+ retval = @layout.frame @layout.from_top_left(width: 10, height: 20)
430
+ retval.should == @view.frame
431
+ end
432
+ @view.frame.origin.x.should == 0
433
+ @view.frame.origin.y.should == 0
434
+ @view.frame.size.width.should == 10
435
+ @view.frame.size.height.should == 20
436
+ end
437
+
438
+ it 'should support setting the frame via `from_top_left(x:y:width:height:)`' do
439
+ @layout.context(@view) do
440
+ retval = @layout.frame @layout.from_top_left(x: 10, y: 20, width: 22, height: 12)
441
+ retval.should == @view.frame
442
+ end
443
+ @view.frame.origin.x.should == 10
444
+ @view.frame.origin.y.should == 20
445
+ @view.frame.size.width.should == 22
446
+ @view.frame.size.height.should == 12
447
+ end
448
+
449
+ it 'should support setting the frame via `from_top_left(right:down:width:height:)`' do
450
+ @layout.context(@view) do
451
+ retval = @layout.frame @layout.from_top_left(right: 10, down: 20, width: 22, height: 12)
452
+ retval.should == @view.frame
453
+ end
454
+ @view.frame.origin.x.should == 10
455
+ @view.frame.origin.y.should == 20
456
+ @view.frame.size.width.should == 22
457
+ @view.frame.size.height.should == 12
458
+ end
459
+
460
+ it 'should support setting the frame via `from_top_left(view)`' do
461
+ @layout.context(@view) do
462
+ retval = @layout.frame @layout.from_top_left(@another_view, x: 1, y: 1)
463
+ retval.should == @view.frame
464
+ end
465
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
466
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
467
+ @view.frame.size.width.should == @view_size.width
468
+ @view.frame.size.height.should == @view_size.height
469
+ end
470
+
471
+ it 'should support setting the frame via `from_top_left(:view)`' do
472
+ @layout.context(@view) do
473
+ retval = @layout.frame @layout.from_top_left(:another_view, x: 1, y: 1)
474
+ retval.should == @view.frame
475
+ end
476
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
477
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
478
+ @view.frame.size.width.should == @view_size.width
479
+ @view.frame.size.height.should == @view_size.height
480
+ end
481
+
482
+ it 'should support setting the frame via `from_top`' do
483
+ @layout.context(@view) do
484
+ retval = @layout.frame @layout.from_top()
485
+ retval.should == @view.frame
486
+ end
487
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
488
+ @view.frame.origin.y.should == 0
489
+ @view.frame.size.width.should == @view_size.width
490
+ @view.frame.size.height.should == @view_size.height
491
+ end
492
+
493
+ it 'should support setting the frame via `from_top(width:height:)`' do
494
+ @layout.context(@view) do
495
+ retval = @layout.frame @layout.from_top(width: 10, height: 20)
496
+ retval.should == @view.frame
497
+ end
498
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
499
+ @view.frame.origin.y.should == 0
500
+ @view.frame.size.width.should == 10
501
+ @view.frame.size.height.should == 20
502
+ end
503
+
504
+ it 'should support setting the frame via `from_top(x:y:width:height:)`' do
505
+ @layout.context(@view) do
506
+ retval = @layout.frame @layout.from_top(x: 10, y: 20, width: 22, height: 12)
507
+ retval.should == @view.frame
508
+ end
509
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
510
+ @view.frame.origin.y.should == 20
511
+ @view.frame.size.width.should == 22
512
+ @view.frame.size.height.should == 12
513
+ end
514
+
515
+ it 'should support setting the frame via `from_top(view)`' do
516
+ @layout.context(@view) do
517
+ retval = @layout.frame @layout.from_top(@another_view, x: 1, y: 1)
518
+ retval.should == @view.frame
519
+ end
520
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
521
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
522
+ @view.frame.size.width.should == @view_size.width
523
+ @view.frame.size.height.should == @view_size.height
524
+ end
525
+
526
+ it 'should support setting the frame via `from_top(view, width: "100%")`' do
527
+ @layout.context(@view) do
528
+ retval = @layout.frame @layout.from_top(@another_view, x: 1, y: 1, width: '100%')
529
+ retval.should == @view.frame
530
+ end
531
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view.frame.size.width) / 2 + 1
532
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
533
+ @view.frame.size.width.should == @superview_size.width
534
+ @view.frame.size.height.should == @view_size.height
535
+ end
536
+
537
+ it 'should support setting the frame via `from_top_right`' do
538
+ @layout.context(@view) do
539
+ retval = @layout.frame @layout.from_top_right()
540
+ retval.should == @view.frame
541
+ end
542
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
543
+ @view.frame.origin.y.should == 0
544
+ @view.frame.size.width.should == @view_size.width
545
+ @view.frame.size.height.should == @view_size.height
546
+ end
547
+
548
+ it 'should support setting the frame via `from_top_right(width:height:)`' do
549
+ @layout.context(@view) do
550
+ retval = @layout.frame @layout.from_top_right(width: 10, height: 20)
551
+ retval.should == @view.frame
552
+ end
553
+ @view.frame.origin.x.should == @superview_size.width - 10
554
+ @view.frame.origin.y.should == 0
555
+ @view.frame.size.width.should == 10
556
+ @view.frame.size.height.should == 20
557
+ end
558
+
559
+ it 'should support setting the frame via `from_top_right(x:y:width:height:)`' do
560
+ @layout.context(@view) do
561
+ retval = @layout.frame @layout.from_top_right(x: 10, y: 20, width: 22, height: 12)
562
+ retval.should == @view.frame
563
+ end
564
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
565
+ @view.frame.origin.y.should == 20
566
+ @view.frame.size.width.should == 22
567
+ @view.frame.size.height.should == 12
568
+ end
569
+
570
+ it 'should support setting the frame via `from_top_right(view)`' do
571
+ @layout.context(@view) do
572
+ retval = @layout.frame @layout.from_top_right(@another_view, x: 1, y: 1)
573
+ retval.should == @view.frame
574
+ end
575
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
576
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
577
+ @view.frame.size.width.should == @view_size.width
578
+ @view.frame.size.height.should == @view_size.height
579
+ end
580
+
581
+ it 'should support setting the frame via `from_left`' do
582
+ @layout.context(@view) do
583
+ retval = @layout.frame @layout.from_left()
584
+ retval.should == @view.frame
585
+ end
586
+ @view.frame.origin.x.should == 0
587
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
588
+ @view.frame.size.width.should == @view_size.width
589
+ @view.frame.size.height.should == @view_size.height
590
+ end
591
+
592
+ it 'should support setting the frame via `from_left(width:height:)`' do
593
+ @layout.context(@view) do
594
+ retval = @layout.frame @layout.from_left(width: 10, height: 20)
595
+ retval.should == @view.frame
596
+ end
597
+ @view.frame.origin.x.should == 0
598
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
599
+ @view.frame.size.width.should == 10
600
+ @view.frame.size.height.should == 20
601
+ end
602
+
603
+ it 'should support setting the frame via `from_left(x:y:width:height:)`' do
604
+ @layout.context(@view) do
605
+ retval = @layout.frame @layout.from_left(x: 10, y: 20, width: 22, height: 12)
606
+ retval.should == @view.frame
607
+ end
608
+ @view.frame.origin.x.should == 10
609
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
610
+ @view.frame.size.width.should == 22
611
+ @view.frame.size.height.should == 12
612
+ end
613
+
614
+ it 'should support setting the frame via `from_left(view)`' do
615
+ @layout.context(@view) do
616
+ retval = @layout.frame @layout.from_left(@another_view, x: 1, y: 1)
617
+ retval.should == @view.frame
618
+ end
619
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
620
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
621
+ @view.frame.size.width.should == @view_size.width
622
+ @view.frame.size.height.should == @view_size.height
623
+ end
624
+
625
+ it 'should support setting the frame via `from_center`' do
626
+ @layout.context(@view) do
627
+ retval = @layout.frame @layout.from_center()
628
+ retval.should == @view.frame
629
+ end
630
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
631
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
632
+ @view.frame.size.width.should == @view_size.width
633
+ @view.frame.size.height.should == @view_size.height
634
+ end
635
+
636
+ it 'should support setting the frame via `from_center(width:height:)`' do
637
+ @layout.context(@view) do
638
+ retval = @layout.frame @layout.from_center(width: 10, height: 20)
639
+ retval.should == @view.frame
640
+ end
641
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
642
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
643
+ @view.frame.size.width.should == 10
644
+ @view.frame.size.height.should == 20
645
+ end
646
+
647
+ it 'should support setting the frame via `from_center(x:y:width:height:)`' do
648
+ @layout.context(@view) do
649
+ retval = @layout.frame @layout.from_center(x: 10, y: 20, width: 22, height: 12)
650
+ retval.should == @view.frame
651
+ end
652
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
653
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
654
+ @view.frame.size.width.should == 22
655
+ @view.frame.size.height.should == 12
656
+ end
657
+
658
+ it 'should support setting the frame via `from_center(view)`' do
659
+ @layout.context(@view) do
660
+ retval = @layout.frame @layout.from_center(@another_view, x: 1, y: 1)
661
+ retval.should == @view.frame
662
+ end
663
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
664
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
665
+ @view.frame.size.width.should == @view_size.width
666
+ @view.frame.size.height.should == @view_size.height
667
+ end
668
+
669
+ it 'should support setting the frame via `from_right`' do
670
+ @layout.context(@view) do
671
+ retval = @layout.frame @layout.from_right()
672
+ retval.should == @view.frame
673
+ end
674
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
675
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
676
+ @view.frame.size.width.should == @view_size.width
677
+ @view.frame.size.height.should == @view_size.height
678
+ end
679
+
680
+ it 'should support setting the frame via `from_right(width:height:)`' do
681
+ @layout.context(@view) do
682
+ retval = @layout.frame @layout.from_right(width: 10, height: 20)
683
+ retval.should == @view.frame
684
+ end
685
+ @view.frame.origin.x.should == @superview_size.width - 10
686
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
687
+ @view.frame.size.width.should == 10
688
+ @view.frame.size.height.should == 20
689
+ end
690
+
691
+ it 'should support setting the frame via `from_right(x:y:width:height:)`' do
692
+ @layout.context(@view) do
693
+ retval = @layout.frame @layout.from_right(x: 10, y: 20, width: 22, height: 12)
694
+ retval.should == @view.frame
695
+ end
696
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
697
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
698
+ @view.frame.size.width.should == 22
699
+ @view.frame.size.height.should == 12
700
+ end
701
+
702
+ it 'should support setting the frame via `from_right(view)`' do
703
+ @layout.context(@view) do
704
+ retval = @layout.frame @layout.from_right(@another_view, x: 1, y: 1)
705
+ retval.should == @view.frame
706
+ end
707
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
708
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
709
+ @view.frame.size.width.should == @view_size.width
710
+ @view.frame.size.height.should == @view_size.height
711
+ end
712
+
713
+ it 'should support setting the frame via `from_bottom_left`' do
714
+ @layout.context(@view) do
715
+ retval = @layout.frame @layout.from_bottom_left()
716
+ retval.should == @view.frame
717
+ end
718
+ @view.frame.origin.x.should == 0
719
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
720
+ @view.frame.size.width.should == @view_size.width
721
+ @view.frame.size.height.should == @view_size.height
722
+ end
723
+
724
+ it 'should support setting the frame via `from_bottom_left(width:height:)`' do
725
+ @layout.context(@view) do
726
+ retval = @layout.frame @layout.from_bottom_left(width: 10, height: 20)
727
+ retval.should == @view.frame
728
+ end
729
+ @view.frame.origin.x.should == 0
730
+ @view.frame.origin.y.should == @superview_size.height - 20
731
+ @view.frame.size.width.should == 10
732
+ @view.frame.size.height.should == 20
733
+ end
734
+
735
+ it 'should support setting the frame via `from_bottom_left(x:y:width:height:)`' do
736
+ @layout.context(@view) do
737
+ retval = @layout.frame @layout.from_bottom_left(x: 10, y: 20, width: 22, height: 12)
738
+ retval.should == @view.frame
739
+ end
740
+ @view.frame.origin.x.should == 10
741
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
742
+ @view.frame.size.width.should == 22
743
+ @view.frame.size.height.should == 12
744
+ end
745
+
746
+ it 'should support setting the frame via `from_bottom_left(view)`' do
747
+ @layout.context(@view) do
748
+ retval = @layout.frame @layout.from_bottom_left(@another_view, x: 1, y: 1)
749
+ retval.should == @view.frame
750
+ end
751
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
752
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
753
+ @view.frame.size.width.should == @view_size.width
754
+ @view.frame.size.height.should == @view_size.height
755
+ end
756
+
757
+ it 'should support setting the frame via `from_bottom`' do
758
+ @layout.context(@view) do
759
+ retval = @layout.frame @layout.from_bottom()
760
+ retval.should == @view.frame
761
+ end
762
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
763
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
764
+ @view.frame.size.width.should == @view_size.width
765
+ @view.frame.size.height.should == @view_size.height
766
+ end
767
+
768
+ it 'should support setting the frame via `from_bottom(width:height:)`' do
769
+ @layout.context(@view) do
770
+ retval = @layout.frame @layout.from_bottom(width: 10, height: 20)
771
+ retval.should == @view.frame
772
+ end
773
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
774
+ @view.frame.origin.y.should == @superview_size.height - 20
775
+ @view.frame.size.width.should == 10
776
+ @view.frame.size.height.should == 20
777
+ end
778
+
779
+ it 'should support setting the frame via `from_bottom(x:y:width:height:)`' do
780
+ @layout.context(@view) do
781
+ retval = @layout.frame @layout.from_bottom(x: 10, y: 20, width: 22, height: 12)
782
+ retval.should == @view.frame
783
+ end
784
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
785
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
786
+ @view.frame.size.width.should == 22
787
+ @view.frame.size.height.should == 12
788
+ end
789
+
790
+ it 'should support setting the frame via `from_bottom(view)`' do
791
+ @layout.context(@view) do
792
+ retval = @layout.frame @layout.from_bottom(@another_view, x: 1, y: 1)
793
+ retval.should == @view.frame
794
+ end
795
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
796
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
797
+ @view.frame.size.width.should == @view_size.width
798
+ @view.frame.size.height.should == @view_size.height
799
+ end
800
+
801
+ it 'should support setting the frame via `from_bottom_right`' do
802
+ @layout.context(@view) do
803
+ retval = @layout.frame @layout.from_bottom_right()
804
+ retval.should == @view.frame
805
+ end
806
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
807
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
808
+ @view.frame.size.width.should == @view_size.width
809
+ @view.frame.size.height.should == @view_size.height
810
+ end
811
+
812
+ it 'should support setting the frame via `from_bottom_right(width:height:)`' do
813
+ @layout.context(@view) do
814
+ retval = @layout.frame @layout.from_bottom_right(width: 10, height: 20)
815
+ retval.should == @view.frame
816
+ end
817
+ @view.frame.origin.x.should == @superview_size.width - 10
818
+ @view.frame.origin.y.should == @superview_size.height - 20
819
+ @view.frame.size.width.should == 10
820
+ @view.frame.size.height.should == 20
821
+ end
822
+
823
+ it 'should support setting the frame via `from_bottom_right(x:y:width:height:)`' do
824
+ @layout.context(@view) do
825
+ retval = @layout.frame @layout.from_bottom_right(x: 10, y: 20, width: 22, height: 12)
826
+ retval.should == @view.frame
827
+ end
828
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
829
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
830
+ @view.frame.size.width.should == 22
831
+ @view.frame.size.height.should == 12
832
+ end
833
+
834
+ it 'should support setting the frame via `from_bottom_right(view)`' do
835
+ @layout.context(@view) do
836
+ retval = @layout.frame @layout.from_bottom_right(@another_view, x: 1, y: 1)
837
+ retval.should == @view.frame
838
+ end
839
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
840
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
841
+ @view.frame.size.width.should == @view_size.width
842
+ @view.frame.size.height.should == @view_size.height
843
+ end
844
+
845
+ it 'should support setting the frame via `above(view)`' do
846
+ @layout.context(@view) do
847
+ retval = @layout.frame @layout.above(@another_view)
848
+ retval.should == @view.frame
849
+ end
850
+ @view.frame.origin.x.should == 10
851
+ @view.frame.origin.y.should == 90
852
+ @view.frame.size.width.should == @view_size.width
853
+ @view.frame.size.height.should == @view_size.height
854
+ end
855
+
856
+ it 'should support setting the frame via `above(view)` and ignore view origin' do
857
+ f = @view.frame
858
+ f.origin.x = 10
859
+ f.origin.y = 10
860
+ @view.frame = f
861
+
862
+ @layout.context(@view) do
863
+ retval = @layout.frame @layout.above(@another_view)
864
+ retval.should == @view.frame
865
+ end
866
+ @view.frame.origin.x.should == 10
867
+ @view.frame.origin.y.should == 90
868
+ @view.frame.size.width.should == @view_size.width
869
+ @view.frame.size.height.should == @view_size.height
870
+ end
871
+
872
+ it 'should support setting the frame via `above(view, up:)`' do
873
+ @layout.context(@view) do
874
+ retval = @layout.frame @layout.above(@another_view, up: 8)
875
+ retval.should == @view.frame
876
+ end
877
+ @view.frame.origin.x.should == 10
878
+ @view.frame.origin.y.should == 82
879
+ @view.frame.size.width.should == @view_size.width
880
+ @view.frame.size.height.should == @view_size.height
881
+ end
882
+
883
+ it 'should support setting the frame via `above(view, width:height:)`' do
884
+ @layout.context(@view) do
885
+ retval = @layout.frame @layout.above(@another_view, width: 10, height: 20)
886
+ retval.should == @view.frame
887
+ end
888
+ @view.frame.origin.x.should == 10
889
+ @view.frame.origin.y.should == 80
890
+ @view.frame.size.width.should == 10
891
+ @view.frame.size.height.should == 20
892
+ end
893
+
894
+ it 'should support setting the frame via `above(view, x:y:width:height:)`' do
895
+ @layout.context(@view) do
896
+ retval = @layout.frame @layout.above(@another_view, x: 10, y: 20, width: 22, height: 12)
897
+ retval.should == @view.frame
898
+ end
899
+ @view.frame.origin.x.should == 20
900
+ @view.frame.origin.y.should == 108
901
+ @view.frame.size.width.should == 22
902
+ @view.frame.size.height.should == 12
903
+ end
904
+
905
+ it 'should support setting the frame via `below(view)`' do
906
+ @layout.context(@view) do
907
+ retval = @layout.frame @layout.below(@another_view)
908
+ retval.should == @view.frame
909
+ end
910
+ @view.frame.origin.x.should == 10
911
+ @view.frame.origin.y.should == 148
912
+ @view.frame.size.width.should == @view_size.width
913
+ @view.frame.size.height.should == @view_size.height
914
+ end
915
+
916
+ it 'should support setting the frame via `below(view)` and ignore view origin' do
917
+ f = @view.frame
918
+ f.origin.x = 10
919
+ f.origin.y = 10
920
+ @view.frame = f
921
+
922
+ @layout.context(@view) do
923
+ retval = @layout.frame @layout.below(@another_view)
924
+ retval.should == @view.frame
925
+ end
926
+ @view.frame.origin.x.should == 10
927
+ @view.frame.origin.y.should == 148
928
+ @view.frame.size.width.should == @view_size.width
929
+ @view.frame.size.height.should == @view_size.height
930
+ end
931
+
932
+ it 'should support setting the frame via `below(view, down:)`' do
933
+ @layout.context(@view) do
934
+ retval = @layout.frame @layout.below(@another_view, down: 8)
935
+ retval.should == @view.frame
936
+ end
937
+ @view.frame.origin.x.should == 10
938
+ @view.frame.origin.y.should == 156
939
+ @view.frame.size.width.should == @view_size.width
940
+ @view.frame.size.height.should == @view_size.height
941
+ end
942
+
943
+ it 'should support setting the frame via `below(view, width:height:)`' do
944
+ @layout.context(@view) do
945
+ retval = @layout.frame @layout.below(@another_view, width: 10, height: 20)
946
+ retval.should == @view.frame
947
+ end
948
+ @view.frame.origin.x.should == 10
949
+ @view.frame.origin.y.should == 148
950
+ @view.frame.size.width.should == 10
951
+ @view.frame.size.height.should == 20
952
+ end
953
+
954
+ it 'should support setting the frame via `below(view, x:y:width:height:)`' do
955
+ @layout.context(@view) do
956
+ retval = @layout.frame @layout.below(@another_view, x: 10, y: 20, width: 22, height: 12)
957
+ retval.should == @view.frame
958
+ end
959
+ @view.frame.origin.x.should == 20
960
+ @view.frame.origin.y.should == 168
961
+ @view.frame.size.width.should == 22
962
+ @view.frame.size.height.should == 12
963
+ end
964
+
965
+ it 'should support setting the frame via `before(view)`' do
966
+ @layout.context(@view) do
967
+ retval = @layout.frame @layout.before(@another_view)
968
+ retval.should == @view.frame
969
+ end
970
+ @view.frame.origin.x.should == 2
971
+ @view.frame.origin.y.should == 100
972
+ @view.frame.size.width.should == @view_size.width
973
+ @view.frame.size.height.should == @view_size.height
974
+ end
975
+
976
+ it 'should support setting the frame via `before(view)` and ignore view origin' do
977
+ f = @view.frame
978
+ f.origin.x = 10
979
+ f.origin.y = 10
980
+ @view.frame = f
981
+
982
+ @layout.context(@view) do
983
+ retval = @layout.frame @layout.before(@another_view)
984
+ retval.should == @view.frame
985
+ end
986
+ @view.frame.origin.x.should == 2
987
+ @view.frame.origin.y.should == 100
988
+ @view.frame.size.width.should == @view_size.width
989
+ @view.frame.size.height.should == @view_size.height
990
+ end
991
+
992
+ it 'should support setting the frame via `before(view, left:)`' do
993
+ @layout.context(@view) do
994
+ retval = @layout.frame @layout.before(@another_view, left: 8)
995
+ retval.should == @view.frame
996
+ end
997
+ @view.frame.origin.x.should == -6
998
+ @view.frame.origin.y.should == 100
999
+ @view.frame.size.width.should == @view_size.width
1000
+ @view.frame.size.height.should == @view_size.height
1001
+ end
1002
+
1003
+ it 'should support setting the frame via `before(view, width:height:)`' do
1004
+ @layout.context(@view) do
1005
+ retval = @layout.frame @layout.before(@another_view, width: 10, height: 20)
1006
+ retval.should == @view.frame
1007
+ end
1008
+ @view.frame.origin.x.should == 0
1009
+ @view.frame.origin.y.should == 100
1010
+ @view.frame.size.width.should == 10
1011
+ @view.frame.size.height.should == 20
1012
+ end
1013
+
1014
+ it 'should support setting the frame via `before(view, x:y:width:height:)`' do
1015
+ @layout.context(@view) do
1016
+ retval = @layout.frame @layout.before(@another_view, x: 10, y: 20, width: 22, height: 12)
1017
+ retval.should == @view.frame
1018
+ end
1019
+ @view.frame.origin.x.should == -2
1020
+ @view.frame.origin.y.should == 120
1021
+ @view.frame.size.width.should == 22
1022
+ @view.frame.size.height.should == 12
1023
+ end
1024
+
1025
+ it 'should support setting the frame via `left_of(view)`' do
1026
+ before = nil
1027
+ left_of = nil
1028
+ @layout.context(@view) do
1029
+ before = @layout.before(@another_view)
1030
+ left_of = @layout.left_of(@another_view)
1031
+ end
1032
+ left_of.origin.x.should == before.origin.x
1033
+ left_of.origin.y.should == before.origin.y
1034
+ left_of.size.width.should == before.size.width
1035
+ left_of.size.height.should == before.size.height
1036
+ end
1037
+
1038
+ it 'should support setting the frame via `after(view)`' do
1039
+ @layout.context(@view) do
1040
+ retval = @layout.frame @layout.after(@another_view)
1041
+ retval.should == @view.frame
1042
+ end
1043
+ @view.frame.origin.x.should == 130
1044
+ @view.frame.origin.y.should == 100
1045
+ @view.frame.size.width.should == @view_size.width
1046
+ @view.frame.size.height.should == @view_size.height
1047
+ end
1048
+
1049
+ it 'should support setting the frame via `after(view)` and ignore view origin' do
1050
+ f = @view.frame
1051
+ f.origin.x = 10
1052
+ f.origin.y = 10
1053
+ @view.frame = f
1054
+
1055
+ @layout.context(@view) do
1056
+ retval = @layout.frame @layout.after(@another_view)
1057
+ retval.should == @view.frame
1058
+ end
1059
+ @view.frame.origin.x.should == 130
1060
+ @view.frame.origin.y.should == 100
1061
+ @view.frame.size.width.should == @view_size.width
1062
+ @view.frame.size.height.should == @view_size.height
1063
+ end
1064
+
1065
+ it 'should support setting the frame via `after(view, right:)`' do
1066
+ @layout.context(@view) do
1067
+ retval = @layout.frame @layout.after(@another_view, right: 8)
1068
+ retval.should == @view.frame
1069
+ end
1070
+ @view.frame.origin.x.should == 138
1071
+ @view.frame.origin.y.should == 100
1072
+ @view.frame.size.width.should == @view_size.width
1073
+ @view.frame.size.height.should == @view_size.height
1074
+ end
1075
+
1076
+ it 'should support setting the frame via `after(view, width:height:)`' do
1077
+ @layout.context(@view) do
1078
+ retval = @layout.frame @layout.after(@another_view, width: 10, height: 20)
1079
+ retval.should == @view.frame
1080
+ end
1081
+ @view.frame.origin.x.should == 130
1082
+ @view.frame.origin.y.should == 100
1083
+ @view.frame.size.width.should == 10
1084
+ @view.frame.size.height.should == 20
1085
+ end
1086
+
1087
+ it 'should support setting the frame via `after(view, x:y:width:height:)`' do
1088
+ @layout.context(@view) do
1089
+ retval = @layout.frame @layout.after(@another_view, x: 10, y: 20, width: 22, height: 12)
1090
+ retval.should == @view.frame
1091
+ end
1092
+ @view.frame.origin.x.should == 140
1093
+ @view.frame.origin.y.should == 120
1094
+ @view.frame.size.width.should == 22
1095
+ @view.frame.size.height.should == 12
1096
+ end
1097
+
1098
+ it 'should support setting the frame via `right_of(view)`' do
1099
+ after = nil
1100
+ right_of = nil
1101
+ @layout.context(@view) do
1102
+ after = @layout.after(@another_view)
1103
+ right_of = @layout.right_of(@another_view)
1104
+ end
1105
+ right_of.origin.x.should == after.origin.x
1106
+ right_of.origin.y.should == after.origin.y
1107
+ right_of.size.width.should == after.size.width
1108
+ right_of.size.height.should == after.size.height
1109
+ end
1110
+
1111
+ it 'should support setting the frame via `relative_to(view)`' do
1112
+ @layout.context(@view) do
1113
+ retval = @layout.frame @layout.relative_to(@another_view, {})
1114
+ retval.should == @view.frame
1115
+ end
1116
+ @view.frame.origin.x.should == 10
1117
+ @view.frame.origin.y.should == 100
1118
+ @view.frame.size.width.should == @view_size.width
1119
+ @view.frame.size.height.should == @view_size.height
1120
+ end
1121
+
1122
+ it 'should support setting the frame via `relative_to(view)` and ignore view origin' do
1123
+ f = @view.frame
1124
+ f.origin.x = 10
1125
+ f.origin.y = 10
1126
+ @view.frame = f
1127
+
1128
+ @layout.context(@view) do
1129
+ retval = @layout.frame @layout.relative_to(@another_view, {})
1130
+ retval.should == @view.frame
1131
+ end
1132
+ @view.frame.origin.x.should == 10
1133
+ @view.frame.origin.y.should == 100
1134
+ @view.frame.size.width.should == @view_size.width
1135
+ @view.frame.size.height.should == @view_size.height
1136
+ end
1137
+
1138
+ it 'should support setting the frame via `relative_to(view, width:height:)`' do
1139
+ @layout.context(@view) do
1140
+ retval = @layout.frame @layout.relative_to(@another_view, width: 10, height: 20)
1141
+ retval.should == @view.frame
1142
+ end
1143
+ @view.frame.origin.x.should == 10
1144
+ @view.frame.origin.y.should == 100
1145
+ @view.frame.size.width.should == 10
1146
+ @view.frame.size.height.should == 20
1147
+ end
1148
+
1149
+ it 'should support setting the frame via `relative_to(view, x:y:width:height:)`' do
1150
+ @layout.context(@view) do
1151
+ retval = @layout.frame @layout.relative_to(@another_view, x: 10, y: 20, width: 22, height: 12)
1152
+ retval.should == @view.frame
1153
+ end
1154
+ @view.frame.origin.x.should == 20
1155
+ @view.frame.origin.y.should == 120
1156
+ @view.frame.size.width.should == 22
1157
+ @view.frame.size.height.should == 12
1158
+ end
1159
+
1160
+ end